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