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 | |
Jason Sams | a6f338c | 2012-02-24 16:22:16 -0800 | [diff] [blame] | 19 | import java.io.File; |
Jason Sams | fe1d5ff | 2012-03-23 11:47:26 -0700 | [diff] [blame] | 20 | import java.lang.reflect.Field; |
Tim Murray | 2f2472c | 2013-08-22 14:55:26 -0700 | [diff] [blame] | 21 | import java.lang.reflect.Method; |
Tim Murray | 504abb3 | 2014-01-07 11:13:56 -0800 | [diff] [blame] | 22 | import java.util.concurrent.locks.ReentrantReadWriteLock; |
Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 23 | |
Shih-wei Liao | 6b32fab | 2010-12-10 01:03:59 -0800 | [diff] [blame] | 24 | import android.content.Context; |
Stephen Hines | 4382467a | 2011-08-01 15:02:34 -0700 | [diff] [blame] | 25 | import android.content.pm.ApplicationInfo; |
| 26 | import android.content.pm.PackageManager; |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 27 | import android.content.res.AssetManager; |
Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 28 | import android.graphics.Bitmap; |
Romain Guy | 650a3eb | 2009-08-31 14:06:43 -0700 | [diff] [blame] | 29 | import android.graphics.BitmapFactory; |
Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 30 | import android.graphics.SurfaceTexture; |
Glenn Kasten | 260c77a | 2011-06-01 17:25:54 -0700 | [diff] [blame] | 31 | import android.os.Process; |
Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 32 | import android.util.Log; |
| 33 | import android.view.Surface; |
Dan Morrill | e4d9a01 | 2013-03-28 18:10:43 -0700 | [diff] [blame] | 34 | import android.os.SystemProperties; |
Tim Murray | 6d7a53c | 2013-05-23 16:59:23 -0700 | [diff] [blame] | 35 | import android.os.Trace; |
Stephen Hines | 4382467a | 2011-08-01 15:02:34 -0700 | [diff] [blame] | 36 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 37 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 38 | * This class provides access to a RenderScript context, which controls RenderScript |
| 39 | * initialization, resource management, and teardown. An instance of the RenderScript |
| 40 | * class must be created before any other RS objects can be created. |
Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 41 | * |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 42 | * <div class="special reference"> |
| 43 | * <h3>Developer Guides</h3> |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 44 | * <p>For more information about creating an application that uses RenderScript, read the |
| 45 | * <a href="{@docRoot}guide/topics/renderscript/index.html">RenderScript</a> developer guide.</p> |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 46 | * </div> |
Jason Sams | e29d471 | 2009-07-23 15:19:03 -0700 | [diff] [blame] | 47 | **/ |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 48 | public class RenderScript { |
Tim Murray | 6d7a53c | 2013-05-23 16:59:23 -0700 | [diff] [blame] | 49 | static final long TRACE_TAG = Trace.TRACE_TAG_RS; |
| 50 | |
Jason Sams | 3bc47d4 | 2009-11-12 15:10:25 -0800 | [diff] [blame] | 51 | static final String LOG_TAG = "RenderScript_jni"; |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 52 | static final boolean DEBUG = false; |
Romain Guy | 650a3eb | 2009-08-31 14:06:43 -0700 | [diff] [blame] | 53 | @SuppressWarnings({"UnusedDeclaration", "deprecation"}) |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 54 | static final boolean LOG_ENABLED = false; |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 55 | |
Shih-wei Liao | 6b32fab | 2010-12-10 01:03:59 -0800 | [diff] [blame] | 56 | private Context mApplicationContext; |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 57 | |
Shih-wei Liao | 6b32fab | 2010-12-10 01:03:59 -0800 | [diff] [blame] | 58 | /* |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 59 | * We use a class initializer to allow the native code to cache some |
| 60 | * field offsets. |
| 61 | */ |
Dan Morrill | e4d9a01 | 2013-03-28 18:10:43 -0700 | [diff] [blame] | 62 | @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"}) // TODO: now used locally; remove? |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 63 | static boolean sInitialized; |
| 64 | native static void _nInit(); |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 65 | |
Tim Murray | 2f2472c | 2013-08-22 14:55:26 -0700 | [diff] [blame] | 66 | static Object sRuntime; |
| 67 | static Method registerNativeAllocation; |
| 68 | static Method registerNativeFree; |
Jason Sams | dba3ba5 | 2009-07-30 14:56:12 -0700 | [diff] [blame] | 69 | |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 70 | static { |
| 71 | sInitialized = false; |
Dan Morrill | e4d9a01 | 2013-03-28 18:10:43 -0700 | [diff] [blame] | 72 | if (!SystemProperties.getBoolean("config.disable_renderscript", false)) { |
| 73 | try { |
Tim Murray | 2f2472c | 2013-08-22 14:55:26 -0700 | [diff] [blame] | 74 | Class<?> vm_runtime = Class.forName("dalvik.system.VMRuntime"); |
| 75 | Method get_runtime = vm_runtime.getDeclaredMethod("getRuntime"); |
| 76 | sRuntime = get_runtime.invoke(null); |
| 77 | registerNativeAllocation = vm_runtime.getDeclaredMethod("registerNativeAllocation", Integer.TYPE); |
| 78 | registerNativeFree = vm_runtime.getDeclaredMethod("registerNativeFree", Integer.TYPE); |
| 79 | } catch (Exception e) { |
| 80 | Log.e(LOG_TAG, "Error loading GC methods: " + e); |
| 81 | throw new RSRuntimeException("Error loading GC methods: " + e); |
| 82 | } |
| 83 | try { |
Dan Morrill | e4d9a01 | 2013-03-28 18:10:43 -0700 | [diff] [blame] | 84 | System.loadLibrary("rs_jni"); |
| 85 | _nInit(); |
| 86 | sInitialized = true; |
| 87 | } catch (UnsatisfiedLinkError e) { |
| 88 | Log.e(LOG_TAG, "Error loading RS jni library: " + e); |
| 89 | throw new RSRuntimeException("Error loading RS jni library: " + e); |
| 90 | } |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 91 | } |
| 92 | } |
| 93 | |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 94 | // Non-threadsafe functions. |
Tim Murray | a78e9ad | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 95 | native long nDeviceCreate(); |
| 96 | native void nDeviceDestroy(long dev); |
| 97 | native void nDeviceSetConfig(long dev, int param, int value); |
| 98 | native int nContextGetUserMessage(long con, int[] data); |
| 99 | native String nContextGetErrorMessage(long con); |
| 100 | native int nContextPeekMessage(long con, int[] subID); |
| 101 | native void nContextInitToClient(long con); |
| 102 | native void nContextDeinitToClient(long con); |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 103 | |
Stephen Hines | 7d25a82 | 2013-04-09 23:51:56 -0700 | [diff] [blame] | 104 | static File mCacheDir; |
Jason Sams | a6f338c | 2012-02-24 16:22:16 -0800 | [diff] [blame] | 105 | |
| 106 | /** |
| 107 | * Sets the directory to use as a persistent storage for the |
| 108 | * renderscript object file cache. |
| 109 | * |
| 110 | * @hide |
| 111 | * @param cacheDir A directory the current process can write to |
| 112 | */ |
Jason Sams | a6f338c | 2012-02-24 16:22:16 -0800 | [diff] [blame] | 113 | public static void setupDiskCache(File cacheDir) { |
Dan Morrill | e4d9a01 | 2013-03-28 18:10:43 -0700 | [diff] [blame] | 114 | if (!sInitialized) { |
| 115 | Log.e(LOG_TAG, "RenderScript.setupDiskCache() called when disabled"); |
| 116 | return; |
| 117 | } |
| 118 | |
Stephen Hines | 7d25a82 | 2013-04-09 23:51:56 -0700 | [diff] [blame] | 119 | // Defer creation of cache path to nScriptCCreate(). |
| 120 | mCacheDir = cacheDir; |
Jason Sams | a6f338c | 2012-02-24 16:22:16 -0800 | [diff] [blame] | 121 | } |
| 122 | |
Jason Sams | 02d56d9 | 2013-04-12 16:40:50 -0700 | [diff] [blame] | 123 | /** |
| 124 | * ContextType specifies the specific type of context to be created. |
| 125 | * |
| 126 | */ |
Jason Sams | add26dc | 2013-02-22 18:43:45 -0800 | [diff] [blame] | 127 | public enum ContextType { |
Jason Sams | 02d56d9 | 2013-04-12 16:40:50 -0700 | [diff] [blame] | 128 | /** |
| 129 | * NORMAL context, this is the default and what shipping apps should |
| 130 | * use. |
| 131 | */ |
Jason Sams | add26dc | 2013-02-22 18:43:45 -0800 | [diff] [blame] | 132 | NORMAL (0), |
Jason Sams | 02d56d9 | 2013-04-12 16:40:50 -0700 | [diff] [blame] | 133 | |
| 134 | /** |
| 135 | * DEBUG context, perform extra runtime checks to validate the |
| 136 | * kernels and APIs are being used as intended. Get and SetElementAt |
| 137 | * will be bounds checked in this mode. |
| 138 | */ |
Jason Sams | add26dc | 2013-02-22 18:43:45 -0800 | [diff] [blame] | 139 | DEBUG (1), |
Jason Sams | 02d56d9 | 2013-04-12 16:40:50 -0700 | [diff] [blame] | 140 | |
| 141 | /** |
| 142 | * PROFILE context, Intended to be used once the first time an |
| 143 | * application is run on a new device. This mode allows the runtime to |
| 144 | * do additional testing and performance tuning. |
| 145 | */ |
Jason Sams | add26dc | 2013-02-22 18:43:45 -0800 | [diff] [blame] | 146 | PROFILE (2); |
| 147 | |
| 148 | int mID; |
| 149 | ContextType(int id) { |
| 150 | mID = id; |
| 151 | } |
| 152 | } |
Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 153 | |
Stephen Hines | 42028a8 | 2013-04-17 19:22:01 -0700 | [diff] [blame] | 154 | ContextType mContextType; |
Tim Murray | 504abb3 | 2014-01-07 11:13:56 -0800 | [diff] [blame] | 155 | ReentrantReadWriteLock mRWLock; |
Stephen Hines | 42028a8 | 2013-04-17 19:22:01 -0700 | [diff] [blame] | 156 | |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 157 | // Methods below are wrapped to protect the non-threadsafe |
| 158 | // lockless fifo. |
Tim Murray | a78e9ad | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 159 | native long rsnContextCreateGL(long dev, int ver, int sdkVer, |
Jason Sams | 11c8af9 | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 160 | int colorMin, int colorPref, |
| 161 | int alphaMin, int alphaPref, |
| 162 | int depthMin, int depthPref, |
| 163 | int stencilMin, int stencilPref, |
Alex Sakhartchouk | 2c74ad9 | 2011-03-16 19:28:25 -0700 | [diff] [blame] | 164 | int samplesMin, int samplesPref, float samplesQ, int dpi); |
Tim Murray | a78e9ad | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 165 | synchronized long nContextCreateGL(long dev, int ver, int sdkVer, |
Jason Sams | 11c8af9 | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 166 | int colorMin, int colorPref, |
| 167 | int alphaMin, int alphaPref, |
| 168 | int depthMin, int depthPref, |
| 169 | int stencilMin, int stencilPref, |
Alex Sakhartchouk | 2c74ad9 | 2011-03-16 19:28:25 -0700 | [diff] [blame] | 170 | int samplesMin, int samplesPref, float samplesQ, int dpi) { |
Stephen Hines | 4382467a | 2011-08-01 15:02:34 -0700 | [diff] [blame] | 171 | return rsnContextCreateGL(dev, ver, sdkVer, colorMin, colorPref, |
Jason Sams | 11c8af9 | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 172 | alphaMin, alphaPref, depthMin, depthPref, |
| 173 | stencilMin, stencilPref, |
Alex Sakhartchouk | 2c74ad9 | 2011-03-16 19:28:25 -0700 | [diff] [blame] | 174 | samplesMin, samplesPref, samplesQ, dpi); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 175 | } |
Tim Murray | a78e9ad | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 176 | native long rsnContextCreate(long dev, int ver, int sdkVer, int contextType); |
| 177 | synchronized long nContextCreate(long dev, int ver, int sdkVer, int contextType) { |
Jason Sams | add26dc | 2013-02-22 18:43:45 -0800 | [diff] [blame] | 178 | return rsnContextCreate(dev, ver, sdkVer, contextType); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 179 | } |
Tim Murray | a78e9ad | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 180 | native void rsnContextDestroy(long con); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 181 | synchronized void nContextDestroy() { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 182 | validate(); |
Tim Murray | 504abb3 | 2014-01-07 11:13:56 -0800 | [diff] [blame] | 183 | |
| 184 | // take teardown lock |
| 185 | // teardown lock can only be taken when no objects are being destroyed |
| 186 | ReentrantReadWriteLock.WriteLock wlock = mRWLock.writeLock(); |
| 187 | wlock.lock(); |
| 188 | |
| 189 | long curCon = mContext; |
| 190 | // context is considered dead as of this point |
| 191 | mContext = 0; |
| 192 | |
| 193 | wlock.unlock(); |
| 194 | rsnContextDestroy(curCon); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 195 | } |
Tim Murray | a78e9ad | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 196 | native void rsnContextSetSurface(long con, int w, int h, Surface sur); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 197 | synchronized void nContextSetSurface(int w, int h, Surface sur) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 198 | validate(); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 199 | rsnContextSetSurface(mContext, w, h, sur); |
| 200 | } |
Tim Murray | a78e9ad | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 201 | native void rsnContextSetSurfaceTexture(long con, int w, int h, SurfaceTexture sur); |
Jason Sams | faa32b3 | 2011-06-20 16:58:04 -0700 | [diff] [blame] | 202 | synchronized void nContextSetSurfaceTexture(int w, int h, SurfaceTexture sur) { |
| 203 | validate(); |
| 204 | rsnContextSetSurfaceTexture(mContext, w, h, sur); |
| 205 | } |
Tim Murray | a78e9ad | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 206 | native void rsnContextSetPriority(long con, int p); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 207 | synchronized void nContextSetPriority(int p) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 208 | validate(); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 209 | rsnContextSetPriority(mContext, p); |
| 210 | } |
Tim Murray | a78e9ad | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 211 | native void rsnContextDump(long con, int bits); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 212 | synchronized void nContextDump(int bits) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 213 | validate(); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 214 | rsnContextDump(mContext, bits); |
| 215 | } |
Tim Murray | a78e9ad | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 216 | native void rsnContextFinish(long con); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 217 | synchronized void nContextFinish() { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 218 | validate(); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 219 | rsnContextFinish(mContext); |
| 220 | } |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 221 | |
Tim Murray | a78e9ad | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 222 | native void rsnContextSendMessage(long con, int id, int[] data); |
Jason Sams | 455d644 | 2013-02-05 19:20:18 -0800 | [diff] [blame] | 223 | synchronized void nContextSendMessage(int id, int[] data) { |
| 224 | validate(); |
| 225 | rsnContextSendMessage(mContext, id, data); |
| 226 | } |
| 227 | |
Tim Murray | a78e9ad | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 228 | native void rsnContextBindRootScript(long con, int script); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 229 | synchronized void nContextBindRootScript(int script) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 230 | validate(); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 231 | rsnContextBindRootScript(mContext, script); |
| 232 | } |
Tim Murray | a78e9ad | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 233 | native void rsnContextBindSampler(long con, int sampler, int slot); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 234 | synchronized void nContextBindSampler(int sampler, int slot) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 235 | validate(); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 236 | rsnContextBindSampler(mContext, sampler, slot); |
| 237 | } |
Tim Murray | a78e9ad | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 238 | native void rsnContextBindProgramStore(long con, int pfs); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 239 | synchronized void nContextBindProgramStore(int pfs) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 240 | validate(); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 241 | rsnContextBindProgramStore(mContext, pfs); |
| 242 | } |
Tim Murray | a78e9ad | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 243 | native void rsnContextBindProgramFragment(long con, int pf); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 244 | synchronized void nContextBindProgramFragment(int pf) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 245 | validate(); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 246 | rsnContextBindProgramFragment(mContext, pf); |
| 247 | } |
Tim Murray | a78e9ad | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 248 | native void rsnContextBindProgramVertex(long con, int pv); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 249 | synchronized void nContextBindProgramVertex(int pv) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 250 | validate(); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 251 | rsnContextBindProgramVertex(mContext, pv); |
| 252 | } |
Tim Murray | a78e9ad | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 253 | native void rsnContextBindProgramRaster(long con, int pr); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 254 | synchronized void nContextBindProgramRaster(int pr) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 255 | validate(); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 256 | rsnContextBindProgramRaster(mContext, pr); |
| 257 | } |
Tim Murray | a78e9ad | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 258 | native void rsnContextPause(long con); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 259 | synchronized void nContextPause() { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 260 | validate(); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 261 | rsnContextPause(mContext); |
| 262 | } |
Tim Murray | a78e9ad | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 263 | native void rsnContextResume(long con); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 264 | synchronized void nContextResume() { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 265 | validate(); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 266 | rsnContextResume(mContext); |
| 267 | } |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 268 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 269 | native void rsnAssignName(long con, long obj, byte[] name); |
| 270 | synchronized void nAssignName(long obj, byte[] name) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 271 | validate(); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 272 | rsnAssignName(mContext, obj, name); |
| 273 | } |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 274 | native String rsnGetName(long con, long obj); |
| 275 | synchronized String nGetName(long obj) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 276 | validate(); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 277 | return rsnGetName(mContext, obj); |
| 278 | } |
Tim Murray | 504abb3 | 2014-01-07 11:13:56 -0800 | [diff] [blame] | 279 | |
| 280 | // nObjDestroy is explicitly _not_ synchronous to prevent crashes in finalizers |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 281 | native void rsnObjDestroy(long con, long id); |
Tim Murray | 504abb3 | 2014-01-07 11:13:56 -0800 | [diff] [blame] | 282 | void nObjDestroy(long id) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 283 | // There is a race condition here. The calling code may be run |
| 284 | // by the gc while teardown is occuring. This protects againts |
| 285 | // deleting dead objects. |
| 286 | if (mContext != 0) { |
| 287 | rsnObjDestroy(mContext, id); |
| 288 | } |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 289 | } |
Jason Sams | fe08d99 | 2009-05-27 14:45:32 -0700 | [diff] [blame] | 290 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 291 | native long rsnElementCreate(long con, long type, int kind, boolean norm, int vecSize); |
| 292 | synchronized long nElementCreate(long type, int kind, boolean norm, int vecSize) { |
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 | return rsnElementCreate(mContext, type, kind, norm, vecSize); |
| 295 | } |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 296 | native long rsnElementCreate2(long con, int[]elements, String[] names, int[] arraySizes); |
| 297 | synchronized long nElementCreate2(int[] elements, String[] names, int[] arraySizes) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 298 | validate(); |
Jason Sams | 70d4e50 | 2010-09-02 17:35:23 -0700 | [diff] [blame] | 299 | return rsnElementCreate2(mContext, elements, names, arraySizes); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 300 | } |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 301 | native void rsnElementGetNativeData(long con, long id, int[] elementData); |
| 302 | synchronized void nElementGetNativeData(long id, int[] elementData) { |
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 | rsnElementGetNativeData(mContext, id, elementData); |
| 305 | } |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 306 | native void rsnElementGetSubElements(long con, long id, |
Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 307 | int[] IDs, String[] names, int[] arraySizes); |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 308 | synchronized void nElementGetSubElements(long id, int[] IDs, String[] names, int[] arraySizes) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 309 | validate(); |
Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 310 | rsnElementGetSubElements(mContext, id, IDs, names, arraySizes); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 311 | } |
Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 312 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 313 | native long rsnTypeCreate(long con, long eid, int x, int y, int z, boolean mips, boolean faces, int yuv); |
| 314 | 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] | 315 | validate(); |
Jason Sams | b109cc7 | 2013-01-07 18:20:12 -0800 | [diff] [blame] | 316 | return rsnTypeCreate(mContext, eid, x, y, z, mips, faces, yuv); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 317 | } |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 318 | native void rsnTypeGetNativeData(long con, long id, int[] typeData); |
| 319 | synchronized void nTypeGetNativeData(long id, int[] typeData) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 320 | validate(); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 321 | rsnTypeGetNativeData(mContext, id, typeData); |
| 322 | } |
Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 323 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 324 | native long rsnAllocationCreateTyped(long con, long type, int mip, int usage, int pointer); |
| 325 | synchronized long nAllocationCreateTyped(long type, int mip, int usage, int pointer) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 326 | validate(); |
Jason Sams | 857d0c7 | 2011-11-23 15:02:15 -0800 | [diff] [blame] | 327 | return rsnAllocationCreateTyped(mContext, type, mip, usage, pointer); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 328 | } |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 329 | native long rsnAllocationCreateFromBitmap(long con, long type, int mip, Bitmap bmp, int usage); |
| 330 | synchronized long nAllocationCreateFromBitmap(long type, int mip, Bitmap bmp, int usage) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 331 | validate(); |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 332 | return rsnAllocationCreateFromBitmap(mContext, type, mip, bmp, usage); |
Alex Sakhartchouk | 26ae390 | 2010-10-11 12:35:15 -0700 | [diff] [blame] | 333 | } |
Tim Murray | a314551 | 2012-12-04 17:59:29 -0800 | [diff] [blame] | 334 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 335 | native long rsnAllocationCreateBitmapBackedAllocation(long con, long type, int mip, Bitmap bmp, int usage); |
| 336 | synchronized long nAllocationCreateBitmapBackedAllocation(long type, int mip, Bitmap bmp, int usage) { |
Tim Murray | a314551 | 2012-12-04 17:59:29 -0800 | [diff] [blame] | 337 | validate(); |
| 338 | return rsnAllocationCreateBitmapBackedAllocation(mContext, type, mip, bmp, usage); |
| 339 | } |
| 340 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 341 | native long rsnAllocationCubeCreateFromBitmap(long con, long type, int mip, Bitmap bmp, int usage); |
| 342 | synchronized long nAllocationCubeCreateFromBitmap(long type, int mip, Bitmap bmp, int usage) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 343 | validate(); |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 344 | return rsnAllocationCubeCreateFromBitmap(mContext, type, mip, bmp, usage); |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 345 | } |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 346 | native long rsnAllocationCreateBitmapRef(long con, long type, Bitmap bmp); |
| 347 | synchronized long nAllocationCreateBitmapRef(long type, Bitmap bmp) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 348 | validate(); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 349 | return rsnAllocationCreateBitmapRef(mContext, type, bmp); |
| 350 | } |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 351 | native long rsnAllocationCreateFromAssetStream(long con, int mips, int assetStream, int usage); |
| 352 | synchronized long nAllocationCreateFromAssetStream(int mips, int assetStream, int usage) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 353 | validate(); |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 354 | return rsnAllocationCreateFromAssetStream(mContext, mips, assetStream, usage); |
| 355 | } |
| 356 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 357 | native void rsnAllocationCopyToBitmap(long con, long alloc, Bitmap bmp); |
| 358 | synchronized void nAllocationCopyToBitmap(long alloc, Bitmap bmp) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 359 | validate(); |
Jason Sams | 4ef6650 | 2010-12-10 16:03:15 -0800 | [diff] [blame] | 360 | rsnAllocationCopyToBitmap(mContext, alloc, bmp); |
| 361 | } |
| 362 | |
| 363 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 364 | native void rsnAllocationSyncAll(long con, long alloc, int src); |
| 365 | synchronized void nAllocationSyncAll(long alloc, int src) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 366 | validate(); |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 367 | rsnAllocationSyncAll(mContext, alloc, src); |
| 368 | } |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 369 | native Surface rsnAllocationGetSurface(long con, long alloc); |
| 370 | synchronized Surface nAllocationGetSurface(long alloc) { |
Jason Sams | 615e7ce | 2012-01-13 14:01:20 -0800 | [diff] [blame] | 371 | validate(); |
Jason Sams | 72226e0 | 2013-02-22 12:45:54 -0800 | [diff] [blame] | 372 | return rsnAllocationGetSurface(mContext, alloc); |
Jason Sams | fe1d5ff | 2012-03-23 11:47:26 -0700 | [diff] [blame] | 373 | } |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 374 | native void rsnAllocationSetSurface(long con, long alloc, Surface sur); |
| 375 | synchronized void nAllocationSetSurface(long alloc, Surface sur) { |
Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 376 | validate(); |
Jason Sams | fb9aa9f | 2012-03-28 15:30:07 -0700 | [diff] [blame] | 377 | rsnAllocationSetSurface(mContext, alloc, sur); |
Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 378 | } |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 379 | native void rsnAllocationIoSend(long con, long alloc); |
| 380 | synchronized void nAllocationIoSend(long alloc) { |
Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 381 | validate(); |
| 382 | rsnAllocationIoSend(mContext, alloc); |
| 383 | } |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 384 | native void rsnAllocationIoReceive(long con, long alloc); |
| 385 | synchronized void nAllocationIoReceive(long alloc) { |
Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 386 | validate(); |
| 387 | rsnAllocationIoReceive(mContext, alloc); |
| 388 | } |
| 389 | |
Jason Sams | 615e7ce | 2012-01-13 14:01:20 -0800 | [diff] [blame] | 390 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 391 | native void rsnAllocationGenerateMipmaps(long con, long alloc); |
| 392 | synchronized void nAllocationGenerateMipmaps(long alloc) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 393 | validate(); |
Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 394 | rsnAllocationGenerateMipmaps(mContext, alloc); |
| 395 | } |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 396 | native void rsnAllocationCopyFromBitmap(long con, long alloc, Bitmap bmp); |
| 397 | synchronized void nAllocationCopyFromBitmap(long alloc, Bitmap bmp) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 398 | validate(); |
Jason Sams | 4ef6650 | 2010-12-10 16:03:15 -0800 | [diff] [blame] | 399 | rsnAllocationCopyFromBitmap(mContext, alloc, bmp); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 400 | } |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 401 | |
Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 402 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 403 | native void rsnAllocationData1D(long con, long id, int off, int mip, int count, Object d, int sizeBytes, int dt); |
| 404 | synchronized void nAllocationData1D(long id, int off, int mip, int count, Object d, int sizeBytes, Element.DataType dt) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 405 | validate(); |
Jason Sams | 6fcf2e1 | 2013-11-06 11:22:02 -0800 | [diff] [blame] | 406 | rsnAllocationData1D(mContext, id, off, mip, count, d, sizeBytes, dt.mID); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 407 | } |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 408 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 409 | native void rsnAllocationElementData1D(long con,long id, int xoff, int mip, int compIdx, byte[] d, int sizeBytes); |
| 410 | synchronized void nAllocationElementData1D(long id, int xoff, int mip, int compIdx, byte[] d, int sizeBytes) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 411 | validate(); |
Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 412 | rsnAllocationElementData1D(mContext, id, xoff, mip, compIdx, d, sizeBytes); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 413 | } |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 414 | |
Tim Murray | a78e9ad | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 415 | native void rsnAllocationData2D(long con, |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 416 | long dstAlloc, int dstXoff, int dstYoff, |
Alex Sakhartchouk | 304b1f5 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 417 | int dstMip, int dstFace, |
| 418 | int width, int height, |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 419 | long srcAlloc, int srcXoff, int srcYoff, |
Alex Sakhartchouk | 304b1f5 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 420 | int srcMip, int srcFace); |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 421 | synchronized void nAllocationData2D(long dstAlloc, int dstXoff, int dstYoff, |
Alex Sakhartchouk | 304b1f5 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 422 | int dstMip, int dstFace, |
| 423 | int width, int height, |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 424 | long srcAlloc, int srcXoff, int srcYoff, |
Alex Sakhartchouk | 304b1f5 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 425 | int srcMip, int srcFace) { |
| 426 | validate(); |
| 427 | rsnAllocationData2D(mContext, |
| 428 | dstAlloc, dstXoff, dstYoff, |
| 429 | dstMip, dstFace, |
| 430 | width, height, |
| 431 | srcAlloc, srcXoff, srcYoff, |
| 432 | srcMip, srcFace); |
| 433 | } |
| 434 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 435 | native void rsnAllocationData2D(long con, long id, int xoff, int yoff, int mip, int face, |
Jason Sams | 6fcf2e1 | 2013-11-06 11:22:02 -0800 | [diff] [blame] | 436 | int w, int h, Object d, int sizeBytes, int dt); |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 437 | synchronized void nAllocationData2D(long id, int xoff, int yoff, int mip, int face, |
Jason Sams | 6fcf2e1 | 2013-11-06 11:22:02 -0800 | [diff] [blame] | 438 | int w, int h, Object d, int sizeBytes, Element.DataType dt) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 439 | validate(); |
Jason Sams | 6fcf2e1 | 2013-11-06 11:22:02 -0800 | [diff] [blame] | 440 | rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes, dt.mID); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 441 | } |
Jason Sams | 29868df | 2013-11-06 15:08:07 -0800 | [diff] [blame] | 442 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 443 | native void rsnAllocationData2D(long con, long id, int xoff, int yoff, int mip, int face, Bitmap b); |
| 444 | 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] | 445 | validate(); |
Jason Sams | fa445b9 | 2011-01-07 17:00:07 -0800 | [diff] [blame] | 446 | rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, b); |
| 447 | } |
Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 448 | |
Tim Murray | a78e9ad | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 449 | native void rsnAllocationData3D(long con, |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 450 | long dstAlloc, int dstXoff, int dstYoff, int dstZoff, |
Jason Sams | b05d689 | 2013-04-09 15:59:24 -0700 | [diff] [blame] | 451 | int dstMip, |
| 452 | int width, int height, int depth, |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 453 | long srcAlloc, int srcXoff, int srcYoff, int srcZoff, |
Jason Sams | b05d689 | 2013-04-09 15:59:24 -0700 | [diff] [blame] | 454 | int srcMip); |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 455 | synchronized void nAllocationData3D(long dstAlloc, int dstXoff, int dstYoff, int dstZoff, |
Jason Sams | b05d689 | 2013-04-09 15:59:24 -0700 | [diff] [blame] | 456 | int dstMip, |
| 457 | int width, int height, int depth, |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 458 | long srcAlloc, int srcXoff, int srcYoff, int srcZoff, |
Jason Sams | b05d689 | 2013-04-09 15:59:24 -0700 | [diff] [blame] | 459 | int srcMip) { |
| 460 | validate(); |
| 461 | rsnAllocationData3D(mContext, |
| 462 | dstAlloc, dstXoff, dstYoff, dstZoff, |
| 463 | dstMip, width, height, depth, |
| 464 | srcAlloc, srcXoff, srcYoff, srcZoff, srcMip); |
| 465 | } |
| 466 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 467 | native void rsnAllocationData3D(long con, long id, int xoff, int yoff, int zoff, int mip, |
Jason Sams | 6fcf2e1 | 2013-11-06 11:22:02 -0800 | [diff] [blame] | 468 | int w, int h, int depth, Object d, int sizeBytes, int dt); |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 469 | synchronized void nAllocationData3D(long id, int xoff, int yoff, int zoff, int mip, |
Jason Sams | 6fcf2e1 | 2013-11-06 11:22:02 -0800 | [diff] [blame] | 470 | int w, int h, int depth, Object d, int sizeBytes, Element.DataType dt) { |
Jason Sams | b05d689 | 2013-04-09 15:59:24 -0700 | [diff] [blame] | 471 | validate(); |
Jason Sams | 6fcf2e1 | 2013-11-06 11:22:02 -0800 | [diff] [blame] | 472 | rsnAllocationData3D(mContext, id, xoff, yoff, zoff, mip, w, h, depth, d, sizeBytes, dt.mID); |
Jason Sams | b05d689 | 2013-04-09 15:59:24 -0700 | [diff] [blame] | 473 | } |
Jason Sams | b05d689 | 2013-04-09 15:59:24 -0700 | [diff] [blame] | 474 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 475 | native void rsnAllocationRead(long con, long id, Object d, int dt); |
| 476 | synchronized void nAllocationRead(long id, Object d, Element.DataType dt) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 477 | validate(); |
Jason Sams | 29868df | 2013-11-06 15:08:07 -0800 | [diff] [blame] | 478 | rsnAllocationRead(mContext, id, d, dt.mID); |
Jason Sams | fa445b9 | 2011-01-07 17:00:07 -0800 | [diff] [blame] | 479 | } |
Jason Sams | 29868df | 2013-11-06 15:08:07 -0800 | [diff] [blame] | 480 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 481 | native void rsnAllocationRead1D(long con, long id, int off, int mip, int count, Object d, |
Jason Sams | 29868df | 2013-11-06 15:08:07 -0800 | [diff] [blame] | 482 | int sizeBytes, int dt); |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 483 | synchronized void nAllocationRead1D(long id, int off, int mip, int count, Object d, |
Jason Sams | 29868df | 2013-11-06 15:08:07 -0800 | [diff] [blame] | 484 | int sizeBytes, Element.DataType dt) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 485 | validate(); |
Jason Sams | 29868df | 2013-11-06 15:08:07 -0800 | [diff] [blame] | 486 | rsnAllocationRead1D(mContext, id, off, mip, count, d, sizeBytes, dt.mID); |
Jason Sams | fa445b9 | 2011-01-07 17:00:07 -0800 | [diff] [blame] | 487 | } |
Jason Sams | 29868df | 2013-11-06 15:08:07 -0800 | [diff] [blame] | 488 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 489 | native void rsnAllocationRead2D(long con, long id, int xoff, int yoff, int mip, int face, |
Jason Sams | 29868df | 2013-11-06 15:08:07 -0800 | [diff] [blame] | 490 | int w, int h, Object d, int sizeBytes, int dt); |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 491 | synchronized void nAllocationRead2D(long id, int xoff, int yoff, int mip, int face, |
Jason Sams | 29868df | 2013-11-06 15:08:07 -0800 | [diff] [blame] | 492 | int w, int h, Object d, int sizeBytes, Element.DataType dt) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 493 | validate(); |
Jason Sams | 29868df | 2013-11-06 15:08:07 -0800 | [diff] [blame] | 494 | rsnAllocationRead2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes, dt.mID); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 495 | } |
Jason Sams | 29868df | 2013-11-06 15:08:07 -0800 | [diff] [blame] | 496 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 497 | native long rsnAllocationGetType(long con, long id); |
| 498 | synchronized long nAllocationGetType(long id) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 499 | validate(); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 500 | return rsnAllocationGetType(mContext, id); |
| 501 | } |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 502 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 503 | native void rsnAllocationResize1D(long con, long id, int dimX); |
| 504 | synchronized void nAllocationResize1D(long id, int dimX) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 505 | validate(); |
Jason Sams | 5edc608 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 506 | rsnAllocationResize1D(mContext, id, dimX); |
| 507 | } |
Jason Sams | 5edc608 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 508 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 509 | native long rsnFileA3DCreateFromAssetStream(long con, int assetStream); |
| 510 | synchronized long nFileA3DCreateFromAssetStream(int assetStream) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 511 | validate(); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 512 | return rsnFileA3DCreateFromAssetStream(mContext, assetStream); |
| 513 | } |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 514 | native long rsnFileA3DCreateFromFile(long con, String path); |
| 515 | synchronized long nFileA3DCreateFromFile(String path) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 516 | validate(); |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 517 | return rsnFileA3DCreateFromFile(mContext, path); |
| 518 | } |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 519 | native long rsnFileA3DCreateFromAsset(long con, AssetManager mgr, String path); |
| 520 | synchronized long nFileA3DCreateFromAsset(AssetManager mgr, String path) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 521 | validate(); |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 522 | return rsnFileA3DCreateFromAsset(mContext, mgr, path); |
| 523 | } |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 524 | native int rsnFileA3DGetNumIndexEntries(long con, long fileA3D); |
| 525 | synchronized int nFileA3DGetNumIndexEntries(long fileA3D) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 526 | validate(); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 527 | return rsnFileA3DGetNumIndexEntries(mContext, fileA3D); |
| 528 | } |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 529 | native void rsnFileA3DGetIndexEntries(long con, long fileA3D, int numEntries, int[] IDs, String[] names); |
| 530 | synchronized void nFileA3DGetIndexEntries(long fileA3D, int numEntries, int[] IDs, String[] names) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 531 | validate(); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 532 | rsnFileA3DGetIndexEntries(mContext, fileA3D, numEntries, IDs, names); |
| 533 | } |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 534 | native int rsnFileA3DGetEntryByIndex(long con, long fileA3D, int index); |
| 535 | synchronized int nFileA3DGetEntryByIndex(long fileA3D, int index) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 536 | validate(); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 537 | return rsnFileA3DGetEntryByIndex(mContext, fileA3D, index); |
| 538 | } |
Jason Sams | bd1c3ad | 2009-08-03 16:03:08 -0700 | [diff] [blame] | 539 | |
Tim Murray | a78e9ad | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 540 | native int rsnFontCreateFromFile(long con, String fileName, float size, int dpi); |
Alex Sakhartchouk | e27cdee | 2010-12-17 11:41:08 -0800 | [diff] [blame] | 541 | synchronized int nFontCreateFromFile(String fileName, float size, int dpi) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 542 | validate(); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 543 | return rsnFontCreateFromFile(mContext, fileName, size, dpi); |
| 544 | } |
Tim Murray | a78e9ad | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 545 | native int rsnFontCreateFromAssetStream(long con, String name, float size, int dpi, int assetStream); |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 546 | synchronized int nFontCreateFromAssetStream(String name, float size, int dpi, int assetStream) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 547 | validate(); |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 548 | return rsnFontCreateFromAssetStream(mContext, name, size, dpi, assetStream); |
| 549 | } |
Tim Murray | a78e9ad | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 550 | native int rsnFontCreateFromAsset(long con, AssetManager mgr, String path, float size, int dpi); |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 551 | synchronized int nFontCreateFromAsset(AssetManager mgr, String path, float size, int dpi) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 552 | validate(); |
Alex Sakhartchouk | b0253ea | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 553 | return rsnFontCreateFromAsset(mContext, mgr, path, size, dpi); |
| 554 | } |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 555 | |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 556 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 557 | native void rsnScriptBindAllocation(long con, long script, long alloc, int slot); |
| 558 | synchronized void nScriptBindAllocation(long script, long alloc, int slot) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 559 | validate(); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 560 | rsnScriptBindAllocation(mContext, script, alloc, slot); |
| 561 | } |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 562 | native void rsnScriptSetTimeZone(long con, long script, byte[] timeZone); |
| 563 | synchronized void nScriptSetTimeZone(long script, byte[] timeZone) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 564 | validate(); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 565 | rsnScriptSetTimeZone(mContext, script, timeZone); |
| 566 | } |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 567 | native void rsnScriptInvoke(long con, long id, int slot); |
| 568 | synchronized void nScriptInvoke(long id, int slot) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 569 | validate(); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 570 | rsnScriptInvoke(mContext, id, slot); |
| 571 | } |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 572 | native void rsnScriptForEach(long con, long id, int slot, long ain, long aout, byte[] params); |
| 573 | native void rsnScriptForEach(long con, long id, int slot, long ain, long aout); |
| 574 | native void rsnScriptForEachClipped(long con, long id, int slot, long ain, long aout, byte[] params, |
Tim Murray | eb8c29c | 2013-02-07 12:16:41 -0800 | [diff] [blame] | 575 | int xstart, int xend, int ystart, int yend, int zstart, int zend); |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 576 | native void rsnScriptForEachClipped(long con, long id, int slot, long ain, long aout, |
Stephen Hines | dac6ed0 | 2013-02-13 00:09:02 -0800 | [diff] [blame] | 577 | int xstart, int xend, int ystart, int yend, int zstart, int zend); |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 578 | synchronized void nScriptForEach(long id, int slot, long ain, long aout, byte[] params) { |
Jason Sams | 6e494d3 | 2011-04-27 16:33:11 -0700 | [diff] [blame] | 579 | validate(); |
| 580 | if (params == null) { |
| 581 | rsnScriptForEach(mContext, id, slot, ain, aout); |
| 582 | } else { |
| 583 | rsnScriptForEach(mContext, id, slot, ain, aout, params); |
| 584 | } |
| 585 | } |
Tim Murray | eb8c29c | 2013-02-07 12:16:41 -0800 | [diff] [blame] | 586 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 587 | synchronized void nScriptForEachClipped(long id, int slot, long ain, long aout, byte[] params, |
Tim Murray | eb8c29c | 2013-02-07 12:16:41 -0800 | [diff] [blame] | 588 | int xstart, int xend, int ystart, int yend, int zstart, int zend) { |
| 589 | validate(); |
Stephen Hines | dac6ed0 | 2013-02-13 00:09:02 -0800 | [diff] [blame] | 590 | if (params == null) { |
| 591 | rsnScriptForEachClipped(mContext, id, slot, ain, aout, xstart, xend, ystart, yend, zstart, zend); |
| 592 | } else { |
| 593 | rsnScriptForEachClipped(mContext, id, slot, ain, aout, params, xstart, xend, ystart, yend, zstart, zend); |
| 594 | } |
Tim Murray | eb8c29c | 2013-02-07 12:16:41 -0800 | [diff] [blame] | 595 | } |
| 596 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 597 | native void rsnScriptInvokeV(long con, long id, int slot, byte[] params); |
| 598 | synchronized void nScriptInvokeV(long id, int slot, byte[] params) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 599 | validate(); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 600 | rsnScriptInvokeV(mContext, id, slot, params); |
| 601 | } |
Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 602 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 603 | native void rsnScriptSetVarI(long con, long id, int slot, int val); |
| 604 | synchronized void nScriptSetVarI(long id, int slot, int val) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 605 | validate(); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 606 | rsnScriptSetVarI(mContext, id, slot, val); |
| 607 | } |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 608 | native int rsnScriptGetVarI(long con, long id, int slot); |
| 609 | synchronized int nScriptGetVarI(long id, int slot) { |
Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 610 | validate(); |
| 611 | return rsnScriptGetVarI(mContext, id, slot); |
| 612 | } |
| 613 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 614 | native void rsnScriptSetVarJ(long con, long id, int slot, long val); |
| 615 | synchronized void nScriptSetVarJ(long id, int slot, long val) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 616 | validate(); |
Stephen Hines | 031ec58c | 2010-10-11 10:54:21 -0700 | [diff] [blame] | 617 | rsnScriptSetVarJ(mContext, id, slot, val); |
| 618 | } |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 619 | native long rsnScriptGetVarJ(long con, long id, int slot); |
| 620 | synchronized long nScriptGetVarJ(long id, int slot) { |
Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 621 | validate(); |
| 622 | return rsnScriptGetVarJ(mContext, id, slot); |
| 623 | } |
| 624 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 625 | native void rsnScriptSetVarF(long con, long id, int slot, float val); |
| 626 | synchronized void nScriptSetVarF(long id, int slot, float val) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 627 | validate(); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 628 | rsnScriptSetVarF(mContext, id, slot, val); |
| 629 | } |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 630 | native float rsnScriptGetVarF(long con, long id, int slot); |
| 631 | synchronized float nScriptGetVarF(long id, int slot) { |
Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 632 | validate(); |
| 633 | return rsnScriptGetVarF(mContext, id, slot); |
| 634 | } |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 635 | native void rsnScriptSetVarD(long con, long id, int slot, double val); |
| 636 | synchronized void nScriptSetVarD(long id, int slot, double val) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 637 | validate(); |
Stephen Hines | ca54ec3 | 2010-09-20 17:20:30 -0700 | [diff] [blame] | 638 | rsnScriptSetVarD(mContext, id, slot, val); |
| 639 | } |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 640 | native double rsnScriptGetVarD(long con, long id, int slot); |
| 641 | synchronized double nScriptGetVarD(long id, int slot) { |
Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 642 | validate(); |
| 643 | return rsnScriptGetVarD(mContext, id, slot); |
| 644 | } |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 645 | native void rsnScriptSetVarV(long con, long id, int slot, byte[] val); |
| 646 | synchronized void nScriptSetVarV(long id, int slot, byte[] val) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 647 | validate(); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 648 | rsnScriptSetVarV(mContext, id, slot, val); |
| 649 | } |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 650 | native void rsnScriptGetVarV(long con, long id, int slot, byte[] val); |
| 651 | synchronized void nScriptGetVarV(long id, int slot, byte[] val) { |
Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 652 | validate(); |
| 653 | rsnScriptGetVarV(mContext, id, slot, val); |
| 654 | } |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 655 | native void rsnScriptSetVarVE(long con, long id, int slot, byte[] val, |
| 656 | long e, int[] dims); |
| 657 | synchronized void nScriptSetVarVE(long id, int slot, byte[] val, |
| 658 | long e, int[] dims) { |
Stephen Hines | adeb809 | 2012-04-20 14:26:06 -0700 | [diff] [blame] | 659 | validate(); |
| 660 | rsnScriptSetVarVE(mContext, id, slot, val, e, dims); |
| 661 | } |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 662 | native void rsnScriptSetVarObj(long con, long id, int slot, long val); |
| 663 | synchronized void nScriptSetVarObj(long id, int slot, long val) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 664 | validate(); |
Jason Sams | 6f4cf0b | 2010-11-16 17:37:02 -0800 | [diff] [blame] | 665 | rsnScriptSetVarObj(mContext, id, slot, val); |
| 666 | } |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 667 | |
Tim Murray | a78e9ad | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 668 | native int rsnScriptCCreate(long con, String resName, String cacheDir, |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 669 | byte[] script, int length); |
| 670 | synchronized int nScriptCCreate(String resName, String cacheDir, byte[] script, int length) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 671 | validate(); |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 672 | return rsnScriptCCreate(mContext, resName, cacheDir, script, length); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 673 | } |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 674 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 675 | native long rsnScriptIntrinsicCreate(long con, int id, long eid); |
| 676 | synchronized long nScriptIntrinsicCreate(int id, long eid) { |
Jason Sams | 6ab9768 | 2012-08-10 12:09:43 -0700 | [diff] [blame] | 677 | validate(); |
| 678 | return rsnScriptIntrinsicCreate(mContext, id, eid); |
| 679 | } |
| 680 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 681 | native long rsnScriptKernelIDCreate(long con, long sid, int slot, int sig); |
| 682 | synchronized long nScriptKernelIDCreate(long sid, int slot, int sig) { |
Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 683 | validate(); |
| 684 | return rsnScriptKernelIDCreate(mContext, sid, slot, sig); |
| 685 | } |
| 686 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 687 | native long rsnScriptFieldIDCreate(long con, long sid, int slot); |
| 688 | synchronized long nScriptFieldIDCreate(long sid, int slot) { |
Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 689 | validate(); |
| 690 | return rsnScriptFieldIDCreate(mContext, sid, slot); |
| 691 | } |
| 692 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 693 | native long rsnScriptGroupCreate(long con, int[] kernels, int[] src, int[] dstk, int[] dstf, int[] types); |
| 694 | synchronized long nScriptGroupCreate(int[] kernels, int[] src, int[] dstk, int[] dstf, int[] types) { |
Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 695 | validate(); |
| 696 | return rsnScriptGroupCreate(mContext, kernels, src, dstk, dstf, types); |
| 697 | } |
| 698 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 699 | native void rsnScriptGroupSetInput(long con, long group, long kernel, long alloc); |
| 700 | synchronized void nScriptGroupSetInput(long group, long kernel, long alloc) { |
Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 701 | validate(); |
| 702 | rsnScriptGroupSetInput(mContext, group, kernel, alloc); |
| 703 | } |
| 704 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 705 | native void rsnScriptGroupSetOutput(long con, long group, long kernel, long alloc); |
| 706 | synchronized void nScriptGroupSetOutput(long group, long kernel, long alloc) { |
Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 707 | validate(); |
| 708 | rsnScriptGroupSetOutput(mContext, group, kernel, alloc); |
| 709 | } |
| 710 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 711 | native void rsnScriptGroupExecute(long con, long group); |
| 712 | synchronized void nScriptGroupExecute(long group) { |
Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 713 | validate(); |
| 714 | rsnScriptGroupExecute(mContext, group); |
| 715 | } |
| 716 | |
Tim Murray | a78e9ad | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 717 | native int rsnSamplerCreate(long con, int magFilter, int minFilter, |
Alex Sakhartchouk | a89094a | 2011-05-04 17:45:36 -0700 | [diff] [blame] | 718 | int wrapS, int wrapT, int wrapR, float aniso); |
| 719 | synchronized int nSamplerCreate(int magFilter, int minFilter, |
| 720 | int wrapS, int wrapT, int wrapR, float aniso) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 721 | validate(); |
Alex Sakhartchouk | a89094a | 2011-05-04 17:45:36 -0700 | [diff] [blame] | 722 | return rsnSamplerCreate(mContext, magFilter, minFilter, wrapS, wrapT, wrapR, aniso); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 723 | } |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 724 | |
Tim Murray | a78e9ad | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 725 | native int rsnProgramStoreCreate(long con, boolean r, boolean g, boolean b, boolean a, |
Jason Sams | 331bf9b | 2011-04-06 11:23:54 -0700 | [diff] [blame] | 726 | boolean depthMask, boolean dither, |
| 727 | int srcMode, int dstMode, int depthFunc); |
| 728 | synchronized int nProgramStoreCreate(boolean r, boolean g, boolean b, boolean a, |
| 729 | boolean depthMask, boolean dither, |
| 730 | int srcMode, int dstMode, int depthFunc) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 731 | validate(); |
Jason Sams | bd184c5 | 2011-04-06 11:44:47 -0700 | [diff] [blame] | 732 | return rsnProgramStoreCreate(mContext, r, g, b, a, depthMask, dither, srcMode, |
| 733 | dstMode, depthFunc); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 734 | } |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 735 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 736 | native long rsnProgramRasterCreate(long con, boolean pointSprite, int cullMode); |
| 737 | synchronized long nProgramRasterCreate(boolean pointSprite, int cullMode) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 738 | validate(); |
Jason Sams | 94aaed3 | 2011-09-23 14:18:53 -0700 | [diff] [blame] | 739 | return rsnProgramRasterCreate(mContext, pointSprite, cullMode); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 740 | } |
Jason Sams | 1fe9b8c | 2009-06-11 14:46:10 -0700 | [diff] [blame] | 741 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 742 | native void rsnProgramBindConstants(long con, long pv, int slot, long mID); |
| 743 | synchronized void nProgramBindConstants(long pv, int slot, long mID) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 744 | validate(); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 745 | rsnProgramBindConstants(mContext, pv, slot, mID); |
| 746 | } |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 747 | native void rsnProgramBindTexture(long con, long vpf, int slot, long a); |
| 748 | synchronized void nProgramBindTexture(long vpf, int slot, long a) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 749 | validate(); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 750 | rsnProgramBindTexture(mContext, vpf, slot, a); |
| 751 | } |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 752 | native void rsnProgramBindSampler(long con, long vpf, int slot, long s); |
| 753 | synchronized void nProgramBindSampler(long vpf, int slot, long s) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 754 | validate(); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 755 | rsnProgramBindSampler(mContext, vpf, slot, s); |
| 756 | } |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 757 | native long rsnProgramFragmentCreate(long con, String shader, String[] texNames, int[] params); |
| 758 | synchronized long nProgramFragmentCreate(String shader, String[] texNames, int[] params) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 759 | validate(); |
Alex Sakhartchouk | 2123b46 | 2012-02-15 16:21:46 -0800 | [diff] [blame] | 760 | return rsnProgramFragmentCreate(mContext, shader, texNames, params); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 761 | } |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 762 | native long rsnProgramVertexCreate(long con, String shader, String[] texNames, int[] params); |
| 763 | synchronized long nProgramVertexCreate(String shader, String[] texNames, int[] params) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 764 | validate(); |
Alex Sakhartchouk | 2123b46 | 2012-02-15 16:21:46 -0800 | [diff] [blame] | 765 | return rsnProgramVertexCreate(mContext, shader, texNames, params); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 766 | } |
Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 767 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 768 | native long rsnMeshCreate(long con, int[] vtx, int[] idx, int[] prim); |
| 769 | synchronized long nMeshCreate(int[] vtx, int[] idx, int[] prim) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 770 | validate(); |
Alex Sakhartchouk | 25999a0 | 2011-05-12 10:38:03 -0700 | [diff] [blame] | 771 | return rsnMeshCreate(mContext, vtx, idx, prim); |
Alex Sakhartchouk | 9d71e21 | 2010-11-08 15:10:52 -0800 | [diff] [blame] | 772 | } |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 773 | native int rsnMeshGetVertexBufferCount(long con, long id); |
| 774 | synchronized int nMeshGetVertexBufferCount(long id) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 775 | validate(); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 776 | return rsnMeshGetVertexBufferCount(mContext, id); |
| 777 | } |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 778 | native int rsnMeshGetIndexCount(long con, long id); |
| 779 | synchronized int nMeshGetIndexCount(long id) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 780 | validate(); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 781 | return rsnMeshGetIndexCount(mContext, id); |
| 782 | } |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 783 | native void rsnMeshGetVertices(long con, long id, int[] vtxIds, int vtxIdCount); |
| 784 | synchronized void nMeshGetVertices(long id, int[] vtxIds, int vtxIdCount) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 785 | validate(); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 786 | rsnMeshGetVertices(mContext, id, vtxIds, vtxIdCount); |
| 787 | } |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 788 | native void rsnMeshGetIndices(long con, long id, int[] idxIds, int[] primitives, int vtxIdCount); |
| 789 | synchronized void nMeshGetIndices(long id, int[] idxIds, int[] primitives, int vtxIdCount) { |
Jason Sams | d1ac981 | 2011-01-18 18:12:26 -0800 | [diff] [blame] | 790 | validate(); |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 791 | rsnMeshGetIndices(mContext, id, idxIds, primitives, vtxIdCount); |
| 792 | } |
| 793 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 794 | native long rsnPathCreate(long con, int prim, boolean isStatic, long vtx, int loop, float q); |
| 795 | synchronized long nPathCreate(int prim, boolean isStatic, long vtx, int loop, float q) { |
Jason Sams | f15ed01 | 2011-10-31 13:23:43 -0700 | [diff] [blame] | 796 | validate(); |
| 797 | return rsnPathCreate(mContext, prim, isStatic, vtx, loop, q); |
| 798 | } |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 799 | |
Tim Murray | a78e9ad | 2013-11-15 13:08:30 -0800 | [diff] [blame] | 800 | long mDev; |
| 801 | long mContext; |
Romain Guy | 650a3eb | 2009-08-31 14:06:43 -0700 | [diff] [blame] | 802 | @SuppressWarnings({"FieldCanBeLocal"}) |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 803 | MessageThread mMessageThread; |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 804 | |
Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 805 | Element mElement_U8; |
| 806 | Element mElement_I8; |
| 807 | Element mElement_U16; |
| 808 | Element mElement_I16; |
| 809 | Element mElement_U32; |
| 810 | Element mElement_I32; |
Stephen Hines | 52d8363 | 2010-10-11 16:10:42 -0700 | [diff] [blame] | 811 | Element mElement_U64; |
Stephen Hines | ef1dac2 | 2010-10-01 15:39:33 -0700 | [diff] [blame] | 812 | Element mElement_I64; |
Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 813 | Element mElement_F32; |
Stephen Hines | 02f41705 | 2010-09-30 15:19:22 -0700 | [diff] [blame] | 814 | Element mElement_F64; |
Jason Sams | f110d4b | 2010-06-21 17:42:41 -0700 | [diff] [blame] | 815 | Element mElement_BOOLEAN; |
Jason Sams | 3c0dfba | 2009-09-27 17:50:38 -0700 | [diff] [blame] | 816 | |
Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 817 | Element mElement_ELEMENT; |
| 818 | Element mElement_TYPE; |
| 819 | Element mElement_ALLOCATION; |
| 820 | Element mElement_SAMPLER; |
| 821 | Element mElement_SCRIPT; |
| 822 | Element mElement_MESH; |
| 823 | Element mElement_PROGRAM_FRAGMENT; |
| 824 | Element mElement_PROGRAM_VERTEX; |
| 825 | Element mElement_PROGRAM_RASTER; |
| 826 | Element mElement_PROGRAM_STORE; |
Stephen Hines | 3a29141 | 2012-04-11 17:27:29 -0700 | [diff] [blame] | 827 | Element mElement_FONT; |
Jason Sams | a70f416 | 2010-03-26 15:33:42 -0700 | [diff] [blame] | 828 | |
Jason Sams | 3c0dfba | 2009-09-27 17:50:38 -0700 | [diff] [blame] | 829 | Element mElement_A_8; |
| 830 | Element mElement_RGB_565; |
| 831 | Element mElement_RGB_888; |
| 832 | Element mElement_RGBA_5551; |
| 833 | Element mElement_RGBA_4444; |
| 834 | Element mElement_RGBA_8888; |
| 835 | |
Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 836 | Element mElement_FLOAT_2; |
| 837 | Element mElement_FLOAT_3; |
| 838 | Element mElement_FLOAT_4; |
Stephen Hines | 836c4a5 | 2011-06-01 14:38:10 -0700 | [diff] [blame] | 839 | |
| 840 | Element mElement_DOUBLE_2; |
| 841 | Element mElement_DOUBLE_3; |
| 842 | Element mElement_DOUBLE_4; |
| 843 | |
| 844 | Element mElement_UCHAR_2; |
| 845 | Element mElement_UCHAR_3; |
Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 846 | Element mElement_UCHAR_4; |
Jason Sams | 7d787b4 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 847 | |
Stephen Hines | 836c4a5 | 2011-06-01 14:38:10 -0700 | [diff] [blame] | 848 | Element mElement_CHAR_2; |
| 849 | Element mElement_CHAR_3; |
| 850 | Element mElement_CHAR_4; |
| 851 | |
| 852 | Element mElement_USHORT_2; |
| 853 | Element mElement_USHORT_3; |
| 854 | Element mElement_USHORT_4; |
| 855 | |
| 856 | Element mElement_SHORT_2; |
| 857 | Element mElement_SHORT_3; |
| 858 | Element mElement_SHORT_4; |
| 859 | |
| 860 | Element mElement_UINT_2; |
| 861 | Element mElement_UINT_3; |
| 862 | Element mElement_UINT_4; |
| 863 | |
| 864 | Element mElement_INT_2; |
| 865 | Element mElement_INT_3; |
| 866 | Element mElement_INT_4; |
| 867 | |
| 868 | Element mElement_ULONG_2; |
| 869 | Element mElement_ULONG_3; |
| 870 | Element mElement_ULONG_4; |
| 871 | |
| 872 | Element mElement_LONG_2; |
| 873 | Element mElement_LONG_3; |
| 874 | Element mElement_LONG_4; |
| 875 | |
Tim Murray | 932e78e | 2013-09-03 11:42:26 -0700 | [diff] [blame] | 876 | Element mElement_YUV; |
| 877 | |
Jason Sams | 1d45c47 | 2010-08-25 14:31:48 -0700 | [diff] [blame] | 878 | Element mElement_MATRIX_4X4; |
| 879 | Element mElement_MATRIX_3X3; |
| 880 | Element mElement_MATRIX_2X2; |
| 881 | |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 882 | Sampler mSampler_CLAMP_NEAREST; |
| 883 | Sampler mSampler_CLAMP_LINEAR; |
| 884 | Sampler mSampler_CLAMP_LINEAR_MIP_LINEAR; |
| 885 | Sampler mSampler_WRAP_NEAREST; |
| 886 | Sampler mSampler_WRAP_LINEAR; |
| 887 | Sampler mSampler_WRAP_LINEAR_MIP_LINEAR; |
Tim Murray | 6b9b2ca | 2013-02-15 13:25:55 -0800 | [diff] [blame] | 888 | Sampler mSampler_MIRRORED_REPEAT_NEAREST; |
| 889 | Sampler mSampler_MIRRORED_REPEAT_LINEAR; |
| 890 | Sampler mSampler_MIRRORED_REPEAT_LINEAR_MIP_LINEAR; |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 891 | |
Alex Sakhartchouk | d36f248 | 2010-08-24 11:37:33 -0700 | [diff] [blame] | 892 | ProgramStore mProgramStore_BLEND_NONE_DEPTH_TEST; |
| 893 | ProgramStore mProgramStore_BLEND_NONE_DEPTH_NO_DEPTH; |
Alex Sakhartchouk | d36f248 | 2010-08-24 11:37:33 -0700 | [diff] [blame] | 894 | ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_TEST; |
| 895 | ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_NO_DEPTH; |
Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame] | 896 | |
Alex Sakhartchouk | d36f248 | 2010-08-24 11:37:33 -0700 | [diff] [blame] | 897 | ProgramRaster mProgramRaster_CULL_BACK; |
| 898 | ProgramRaster mProgramRaster_CULL_FRONT; |
| 899 | ProgramRaster mProgramRaster_CULL_NONE; |
Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame] | 900 | |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 901 | /////////////////////////////////////////////////////////////////////////////////// |
Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 902 | // |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 903 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 904 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 905 | * The base class from which an application should derive in order |
| 906 | * to receive RS messages from scripts. When a script calls {@code |
| 907 | * rsSendToClient}, the data fields will be filled, and the run |
| 908 | * method will be called on a separate thread. This will occur |
| 909 | * some time after {@code rsSendToClient} completes in the script, |
| 910 | * as {@code rsSendToClient} is asynchronous. Message handlers are |
| 911 | * not guaranteed to have completed when {@link |
| 912 | * android.renderscript.RenderScript#finish} returns. |
Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 913 | * |
| 914 | */ |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 915 | public static class RSMessageHandler implements Runnable { |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 916 | protected int[] mData; |
| 917 | protected int mID; |
Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 918 | protected int mLength; |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 919 | public void run() { |
| 920 | } |
| 921 | } |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 922 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 923 | * If an application is expecting messages, it should set this |
| 924 | * field to an instance of {@link RSMessageHandler}. This |
| 925 | * instance will receive all the user messages sent from {@code |
| 926 | * sendToClient} by scripts from this context. |
Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 927 | * |
| 928 | */ |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 929 | RSMessageHandler mMessageCallback = null; |
| 930 | |
| 931 | public void setMessageHandler(RSMessageHandler msg) { |
| 932 | mMessageCallback = msg; |
| 933 | } |
| 934 | public RSMessageHandler getMessageHandler() { |
| 935 | return mMessageCallback; |
| 936 | } |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 937 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 938 | /** |
Jason Sams | 02d56d9 | 2013-04-12 16:40:50 -0700 | [diff] [blame] | 939 | * Place a message into the message queue to be sent back to the message |
| 940 | * handler once all previous commands have been executed. |
Jason Sams | 455d644 | 2013-02-05 19:20:18 -0800 | [diff] [blame] | 941 | * |
| 942 | * @param id |
| 943 | * @param data |
| 944 | */ |
| 945 | public void sendMessage(int id, int[] data) { |
| 946 | nContextSendMessage(id, data); |
| 947 | } |
| 948 | |
| 949 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 950 | * The runtime error handler base class. An application should derive from this class |
| 951 | * if it wishes to install an error handler. When errors occur at runtime, |
| 952 | * 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] | 953 | * |
| 954 | */ |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 955 | public static class RSErrorHandler implements Runnable { |
Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 956 | protected String mErrorMessage; |
| 957 | protected int mErrorNum; |
| 958 | public void run() { |
| 959 | } |
| 960 | } |
Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 961 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 962 | /** |
Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 963 | * Application Error handler. All runtime errors will be dispatched to the |
| 964 | * instance of RSAsyncError set here. If this field is null a |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 965 | * {@link RSRuntimeException} will instead be thrown with details about the error. |
Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 966 | * This will cause program termaination. |
| 967 | * |
| 968 | */ |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 969 | RSErrorHandler mErrorCallback = null; |
| 970 | |
| 971 | public void setErrorHandler(RSErrorHandler msg) { |
| 972 | mErrorCallback = msg; |
| 973 | } |
| 974 | public RSErrorHandler getErrorHandler() { |
| 975 | return mErrorCallback; |
| 976 | } |
Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 977 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 978 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 979 | * RenderScript worker thread priority enumeration. The default value is |
| 980 | * NORMAL. Applications wishing to do background processing should set |
| 981 | * their priority to LOW to avoid starving forground processes. |
Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 982 | */ |
Jason Sams | 7d787b4 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 983 | public enum Priority { |
Glenn Kasten | 260c77a | 2011-06-01 17:25:54 -0700 | [diff] [blame] | 984 | LOW (Process.THREAD_PRIORITY_BACKGROUND + (5 * Process.THREAD_PRIORITY_LESS_FAVORABLE)), |
| 985 | NORMAL (Process.THREAD_PRIORITY_DISPLAY); |
Jason Sams | 7d787b4 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 986 | |
| 987 | int mID; |
| 988 | Priority(int id) { |
| 989 | mID = id; |
| 990 | } |
| 991 | } |
| 992 | |
Jason Sams | 771bebb | 2009-12-07 12:40:12 -0800 | [diff] [blame] | 993 | void validate() { |
| 994 | if (mContext == 0) { |
Jason Sams | c1d6210 | 2010-11-04 14:32:19 -0700 | [diff] [blame] | 995 | throw new RSInvalidStateException("Calling RS with no Context active."); |
Jason Sams | 771bebb | 2009-12-07 12:40:12 -0800 | [diff] [blame] | 996 | } |
| 997 | } |
| 998 | |
Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 999 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1000 | /** |
Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 1001 | * Change the priority of the worker threads for this context. |
| 1002 | * |
| 1003 | * @param p New priority to be set. |
| 1004 | */ |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 1005 | public void setPriority(Priority p) { |
Jason Sams | 5dbfe93 | 2010-01-27 14:41:43 -0800 | [diff] [blame] | 1006 | validate(); |
Jason Sams | 7d787b4 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 1007 | nContextSetPriority(p.mID); |
| 1008 | } |
| 1009 | |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 1010 | static class MessageThread extends Thread { |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 1011 | RenderScript mRS; |
| 1012 | boolean mRun = true; |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 1013 | int[] mAuxData = new int[2]; |
Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 1014 | |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 1015 | static final int RS_MESSAGE_TO_CLIENT_NONE = 0; |
| 1016 | static final int RS_MESSAGE_TO_CLIENT_EXCEPTION = 1; |
| 1017 | static final int RS_MESSAGE_TO_CLIENT_RESIZE = 2; |
| 1018 | static final int RS_MESSAGE_TO_CLIENT_ERROR = 3; |
| 1019 | static final int RS_MESSAGE_TO_CLIENT_USER = 4; |
Jason Sams | 739c826 | 2013-04-11 18:07:52 -0700 | [diff] [blame] | 1020 | static final int RS_MESSAGE_TO_CLIENT_NEW_BUFFER = 5; |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 1021 | |
Stephen Hines | 42028a8 | 2013-04-17 19:22:01 -0700 | [diff] [blame] | 1022 | static final int RS_ERROR_FATAL_DEBUG = 0x0800; |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 1023 | static final int RS_ERROR_FATAL_UNKNOWN = 0x1000; |
Jason Sams | add9d96 | 2010-11-22 16:20:16 -0800 | [diff] [blame] | 1024 | |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 1025 | MessageThread(RenderScript rs) { |
| 1026 | super("RSMessageThread"); |
| 1027 | mRS = rs; |
| 1028 | |
| 1029 | } |
| 1030 | |
| 1031 | public void run() { |
| 1032 | // This function is a temporary solution. The final solution will |
| 1033 | // used typed allocations where the message id is the type indicator. |
| 1034 | int[] rbuf = new int[16]; |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1035 | mRS.nContextInitToClient(mRS.mContext); |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 1036 | while(mRun) { |
Jason Sams | 1d45c47 | 2010-08-25 14:31:48 -0700 | [diff] [blame] | 1037 | rbuf[0] = 0; |
Jason Sams | edbfabd | 2011-05-17 15:01:29 -0700 | [diff] [blame] | 1038 | int msg = mRS.nContextPeekMessage(mRS.mContext, mAuxData); |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 1039 | int size = mAuxData[1]; |
| 1040 | int subID = mAuxData[0]; |
Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 1041 | |
| 1042 | if (msg == RS_MESSAGE_TO_CLIENT_USER) { |
| 1043 | if ((size>>2) >= rbuf.length) { |
| 1044 | rbuf = new int[(size + 3) >> 2]; |
| 1045 | } |
Jason Sams | edbfabd | 2011-05-17 15:01:29 -0700 | [diff] [blame] | 1046 | if (mRS.nContextGetUserMessage(mRS.mContext, rbuf) != |
| 1047 | RS_MESSAGE_TO_CLIENT_USER) { |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1048 | throw new RSDriverException("Error processing message from RenderScript."); |
Jason Sams | edbfabd | 2011-05-17 15:01:29 -0700 | [diff] [blame] | 1049 | } |
Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 1050 | |
| 1051 | if(mRS.mMessageCallback != null) { |
| 1052 | mRS.mMessageCallback.mData = rbuf; |
| 1053 | mRS.mMessageCallback.mID = subID; |
| 1054 | mRS.mMessageCallback.mLength = size; |
| 1055 | mRS.mMessageCallback.run(); |
Jason Sams | 1d45c47 | 2010-08-25 14:31:48 -0700 | [diff] [blame] | 1056 | } else { |
Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 1057 | 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] | 1058 | } |
Stephen Hines | ab98bb6 | 2010-09-24 14:38:30 -0700 | [diff] [blame] | 1059 | continue; |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 1060 | } |
Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 1061 | |
| 1062 | if (msg == RS_MESSAGE_TO_CLIENT_ERROR) { |
| 1063 | String e = mRS.nContextGetErrorMessage(mRS.mContext); |
| 1064 | |
Stephen Hines | 42028a8 | 2013-04-17 19:22:01 -0700 | [diff] [blame] | 1065 | // Throw RSRuntimeException under the following conditions: |
| 1066 | // |
| 1067 | // 1) It is an unknown fatal error. |
| 1068 | // 2) It is a debug fatal error, and we are not in a |
| 1069 | // debug context. |
| 1070 | // 3) It is a debug fatal error, and we do not have an |
| 1071 | // error callback. |
| 1072 | if (subID >= RS_ERROR_FATAL_UNKNOWN || |
| 1073 | (subID >= RS_ERROR_FATAL_DEBUG && |
| 1074 | (mRS.mContextType != ContextType.DEBUG || |
| 1075 | mRS.mErrorCallback == null))) { |
Jason Sams | add9d96 | 2010-11-22 16:20:16 -0800 | [diff] [blame] | 1076 | throw new RSRuntimeException("Fatal error " + subID + ", details: " + e); |
| 1077 | } |
| 1078 | |
Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 1079 | if(mRS.mErrorCallback != null) { |
| 1080 | mRS.mErrorCallback.mErrorMessage = e; |
| 1081 | mRS.mErrorCallback.mErrorNum = subID; |
| 1082 | mRS.mErrorCallback.run(); |
| 1083 | } else { |
Jason Sams | a4b7bc9 | 2013-02-05 15:05:39 -0800 | [diff] [blame] | 1084 | android.util.Log.e(LOG_TAG, "non fatal RS error, " + e); |
Stephen Hines | be74bdd | 2012-02-03 15:29:36 -0800 | [diff] [blame] | 1085 | // Do not throw here. In these cases, we do not have |
| 1086 | // a fatal error. |
Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 1087 | } |
| 1088 | continue; |
| 1089 | } |
| 1090 | |
Jason Sams | 739c826 | 2013-04-11 18:07:52 -0700 | [diff] [blame] | 1091 | if (msg == RS_MESSAGE_TO_CLIENT_NEW_BUFFER) { |
| 1092 | Allocation.sendBufferNotification(subID); |
| 1093 | continue; |
| 1094 | } |
| 1095 | |
Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 1096 | // 2: teardown. |
| 1097 | // But we want to avoid starving other threads during |
| 1098 | // teardown by yielding until the next line in the destructor |
| 1099 | // can execute to set mRun = false |
| 1100 | try { |
| 1101 | sleep(1, 0); |
| 1102 | } catch(InterruptedException e) { |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 1103 | } |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 1104 | } |
Tim Murray | da67deb | 2013-05-09 12:02:50 -0700 | [diff] [blame] | 1105 | //Log.d(LOG_TAG, "MessageThread exiting."); |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 1106 | } |
| 1107 | } |
| 1108 | |
Shih-wei Liao | 6b32fab | 2010-12-10 01:03:59 -0800 | [diff] [blame] | 1109 | RenderScript(Context ctx) { |
Stephen Hines | 42028a8 | 2013-04-17 19:22:01 -0700 | [diff] [blame] | 1110 | mContextType = ContextType.NORMAL; |
Jason Sams | 1a4e1f3 | 2012-02-24 17:51:24 -0800 | [diff] [blame] | 1111 | if (ctx != null) { |
| 1112 | mApplicationContext = ctx.getApplicationContext(); |
| 1113 | } |
Tim Murray | 504abb3 | 2014-01-07 11:13:56 -0800 | [diff] [blame] | 1114 | mRWLock = new ReentrantReadWriteLock(); |
Shih-wei Liao | 6b32fab | 2010-12-10 01:03:59 -0800 | [diff] [blame] | 1115 | } |
| 1116 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1117 | /** |
Shih-wei Liao | 6b32fab | 2010-12-10 01:03:59 -0800 | [diff] [blame] | 1118 | * Gets the application context associated with the RenderScript context. |
| 1119 | * |
| 1120 | * @return The application context. |
| 1121 | */ |
| 1122 | public final Context getApplicationContext() { |
| 1123 | return mApplicationContext; |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 1124 | } |
| 1125 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1126 | /** |
Jason Sams | add26dc | 2013-02-22 18:43:45 -0800 | [diff] [blame] | 1127 | * @hide |
| 1128 | */ |
| 1129 | public static RenderScript create(Context ctx, int sdkVersion) { |
| 1130 | return create(ctx, sdkVersion, ContextType.NORMAL); |
| 1131 | } |
| 1132 | |
| 1133 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1134 | * Create a RenderScript context. |
Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 1135 | * |
Jason Sams | 1a4e1f3 | 2012-02-24 17:51:24 -0800 | [diff] [blame] | 1136 | * @hide |
Shih-wei Liao | 6b32fab | 2010-12-10 01:03:59 -0800 | [diff] [blame] | 1137 | * @param ctx The context. |
Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 1138 | * @return RenderScript |
| 1139 | */ |
Jason Sams | add26dc | 2013-02-22 18:43:45 -0800 | [diff] [blame] | 1140 | public static RenderScript create(Context ctx, int sdkVersion, ContextType ct) { |
Dan Morrill | e4d9a01 | 2013-03-28 18:10:43 -0700 | [diff] [blame] | 1141 | if (!sInitialized) { |
| 1142 | Log.e(LOG_TAG, "RenderScript.create() called when disabled; someone is likely to crash"); |
| 1143 | return null; |
| 1144 | } |
| 1145 | |
Shih-wei Liao | 6b32fab | 2010-12-10 01:03:59 -0800 | [diff] [blame] | 1146 | RenderScript rs = new RenderScript(ctx); |
Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 1147 | |
| 1148 | rs.mDev = rs.nDeviceCreate(); |
Jason Sams | add26dc | 2013-02-22 18:43:45 -0800 | [diff] [blame] | 1149 | rs.mContext = rs.nContextCreate(rs.mDev, 0, sdkVersion, ct.mID); |
Stephen Hines | 42028a8 | 2013-04-17 19:22:01 -0700 | [diff] [blame] | 1150 | rs.mContextType = ct; |
Jason Sams | 2698536 | 2011-05-03 15:01:58 -0700 | [diff] [blame] | 1151 | if (rs.mContext == 0) { |
| 1152 | throw new RSDriverException("Failed to create RS context."); |
| 1153 | } |
Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 1154 | rs.mMessageThread = new MessageThread(rs); |
| 1155 | rs.mMessageThread.start(); |
Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 1156 | return rs; |
Jason Sams | efd9b6fb | 2009-11-03 13:58:36 -0800 | [diff] [blame] | 1157 | } |
| 1158 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1159 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1160 | * Create a RenderScript context. |
Jason Sams | 1a4e1f3 | 2012-02-24 17:51:24 -0800 | [diff] [blame] | 1161 | * |
| 1162 | * @param ctx The context. |
| 1163 | * @return RenderScript |
| 1164 | */ |
| 1165 | public static RenderScript create(Context ctx) { |
Jason Sams | add26dc | 2013-02-22 18:43:45 -0800 | [diff] [blame] | 1166 | return create(ctx, ContextType.NORMAL); |
| 1167 | } |
| 1168 | |
| 1169 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1170 | * Create a RenderScript context. |
Jason Sams | add26dc | 2013-02-22 18:43:45 -0800 | [diff] [blame] | 1171 | * |
Jason Sams | add26dc | 2013-02-22 18:43:45 -0800 | [diff] [blame] | 1172 | * |
| 1173 | * @param ctx The context. |
Jason Sams | 02d56d9 | 2013-04-12 16:40:50 -0700 | [diff] [blame] | 1174 | * @param ct The type of context to be created. |
Jason Sams | add26dc | 2013-02-22 18:43:45 -0800 | [diff] [blame] | 1175 | * @return RenderScript |
| 1176 | */ |
| 1177 | public static RenderScript create(Context ctx, ContextType ct) { |
Jason Sams | 1a4e1f3 | 2012-02-24 17:51:24 -0800 | [diff] [blame] | 1178 | int v = ctx.getApplicationInfo().targetSdkVersion; |
Jason Sams | add26dc | 2013-02-22 18:43:45 -0800 | [diff] [blame] | 1179 | return create(ctx, v, ct); |
Jason Sams | 1a4e1f3 | 2012-02-24 17:51:24 -0800 | [diff] [blame] | 1180 | } |
| 1181 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1182 | /** |
Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 1183 | * Print the currently available debugging information about the state of |
| 1184 | * the RS context to the log. |
| 1185 | * |
Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 1186 | */ |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 1187 | public void contextDump() { |
Jason Sams | 5dbfe93 | 2010-01-27 14:41:43 -0800 | [diff] [blame] | 1188 | validate(); |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 1189 | nContextDump(0); |
Jason Sams | 715333b | 2009-11-17 17:26:46 -0800 | [diff] [blame] | 1190 | } |
| 1191 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1192 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1193 | * Wait for any pending asynchronous opeations (such as copies to a RS |
| 1194 | * allocation or RS script executions) to complete. |
Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 1195 | * |
| 1196 | */ |
Jason Sams | 96ed4cf | 2010-06-15 12:15:57 -0700 | [diff] [blame] | 1197 | public void finish() { |
| 1198 | nContextFinish(); |
| 1199 | } |
| 1200 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1201 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1202 | * Destroys this RenderScript context. Once this function is called, |
| 1203 | * using this context or any objects belonging to this context is |
| 1204 | * illegal. |
Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 1205 | * |
| 1206 | */ |
Jason Sams | f5b4596 | 2009-08-25 14:49:07 -0700 | [diff] [blame] | 1207 | public void destroy() { |
Jason Sams | 5dbfe93 | 2010-01-27 14:41:43 -0800 | [diff] [blame] | 1208 | validate(); |
Tim Murray | 504abb3 | 2014-01-07 11:13:56 -0800 | [diff] [blame] | 1209 | nContextFinish(); |
| 1210 | |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1211 | nContextDeinitToClient(mContext); |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 1212 | mMessageThread.mRun = false; |
Jason Sams | a8bf942 | 2010-09-16 13:43:19 -0700 | [diff] [blame] | 1213 | try { |
| 1214 | mMessageThread.join(); |
| 1215 | } catch(InterruptedException e) { |
| 1216 | } |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 1217 | |
Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 1218 | nContextDestroy(); |
Jason Sams | f5b4596 | 2009-08-25 14:49:07 -0700 | [diff] [blame] | 1219 | |
| 1220 | nDeviceDestroy(mDev); |
| 1221 | mDev = 0; |
| 1222 | } |
Jason Sams | 02fb2cb | 2009-05-28 15:37:57 -0700 | [diff] [blame] | 1223 | |
Jason Sams | a9e7a05 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 1224 | boolean isAlive() { |
| 1225 | return mContext != 0; |
| 1226 | } |
| 1227 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1228 | long safeID(BaseObj o) { |
Jason Sams | 6b9dec0 | 2009-09-23 16:38:37 -0700 | [diff] [blame] | 1229 | if(o != null) { |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 1230 | return o.getID(this); |
Jason Sams | d8e4161 | 2009-08-20 17:22:40 -0700 | [diff] [blame] | 1231 | } |
Jason Sams | 6b9dec0 | 2009-09-23 16:38:37 -0700 | [diff] [blame] | 1232 | return 0; |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 1233 | } |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 1234 | } |