| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 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 | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 19 | import java.lang.reflect.Field; |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 20 | |
| Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 21 | import android.graphics.Bitmap; |
| Romain Guy | 650a3eb | 2009-08-31 14:06:43 -0700 | [diff] [blame] | 22 | import android.graphics.BitmapFactory; |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 23 | import android.util.Config; |
| 24 | import android.util.Log; |
| 25 | import android.view.Surface; |
| Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 26 | |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 27 | |
| Jason Sams | e29d471 | 2009-07-23 15:19:03 -0700 | [diff] [blame] | 28 | /** |
| 29 | * @hide |
| 30 | * |
| Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 31 | * RenderScript base master class. An instance of this class creates native |
| 32 | * worker threads for processing commands from this object. This base class |
| 33 | * does not provide any extended capabilities beyond simple data processing. |
| 34 | * For extended capabilities use derived classes such as RenderScriptGL. |
| 35 | * |
| 36 | * |
| 37 | * |
| Jason Sams | e29d471 | 2009-07-23 15:19:03 -0700 | [diff] [blame] | 38 | **/ |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 39 | public class RenderScript { |
| Jason Sams | 3bc47d4 | 2009-11-12 15:10:25 -0800 | [diff] [blame] | 40 | static final String LOG_TAG = "RenderScript_jni"; |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 41 | static final boolean DEBUG = false; |
| Romain Guy | 650a3eb | 2009-08-31 14:06:43 -0700 | [diff] [blame] | 42 | @SuppressWarnings({"UnusedDeclaration", "deprecation"}) |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 43 | static final boolean LOG_ENABLED = DEBUG ? Config.LOGD : Config.LOGV; |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 44 | |
| 45 | |
| 46 | |
| Jason Sams | 02fb2cb | 2009-05-28 15:37:57 -0700 | [diff] [blame] | 47 | /* |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 48 | * We use a class initializer to allow the native code to cache some |
| 49 | * field offsets. |
| 50 | */ |
| Romain Guy | 650a3eb | 2009-08-31 14:06:43 -0700 | [diff] [blame] | 51 | @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"}) |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 52 | static boolean sInitialized; |
| 53 | native static void _nInit(); |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 54 | |
| Jason Sams | dba3ba5 | 2009-07-30 14:56:12 -0700 | [diff] [blame] | 55 | |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 56 | static { |
| 57 | sInitialized = false; |
| 58 | try { |
| Jason Sams | e29d471 | 2009-07-23 15:19:03 -0700 | [diff] [blame] | 59 | System.loadLibrary("rs_jni"); |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 60 | _nInit(); |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 61 | sInitialized = true; |
| 62 | } catch (UnsatisfiedLinkError e) { |
| 63 | Log.d(LOG_TAG, "RenderScript JNI library not found!"); |
| 64 | } |
| 65 | } |
| 66 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 67 | // Non-threadsafe functions. |
| Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame] | 68 | native int nDeviceCreate(); |
| 69 | native void nDeviceDestroy(int dev); |
| Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 70 | native void nDeviceSetConfig(int dev, int param, int value); |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 71 | native void nContextGetUserMessage(int con, int[] data); |
| 72 | native String nContextGetErrorMessage(int con); |
| 73 | native int nContextPeekMessage(int con, int[] subID, boolean wait); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 74 | native void nContextInitToClient(int con); |
| 75 | native void nContextDeinitToClient(int con); |
| Jason Sams | 3eaa338e | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 76 | |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 77 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 78 | // Methods below are wrapped to protect the non-threadsafe |
| 79 | // lockless fifo. |
| Jason Sams | 11c8af9 | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 80 | native int rsnContextCreateGL(int dev, int ver, |
| 81 | int colorMin, int colorPref, |
| 82 | int alphaMin, int alphaPref, |
| 83 | int depthMin, int depthPref, |
| 84 | int stencilMin, int stencilPref, |
| 85 | int samplesMin, int samplesPref, float samplesQ); |
| 86 | synchronized int nContextCreateGL(int dev, int ver, |
| 87 | int colorMin, int colorPref, |
| 88 | int alphaMin, int alphaPref, |
| 89 | int depthMin, int depthPref, |
| 90 | int stencilMin, int stencilPref, |
| 91 | int samplesMin, int samplesPref, float samplesQ) { |
| 92 | return rsnContextCreateGL(dev, ver, colorMin, colorPref, |
| 93 | alphaMin, alphaPref, depthMin, depthPref, |
| 94 | stencilMin, stencilPref, |
| 95 | samplesMin, samplesPref, samplesQ); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 96 | } |
| 97 | native int rsnContextCreate(int dev, int ver); |
| 98 | synchronized int nContextCreate(int dev, int ver) { |
| 99 | return rsnContextCreate(dev, ver); |
| 100 | } |
| 101 | native void rsnContextDestroy(int con); |
| 102 | synchronized void nContextDestroy() { |
| 103 | rsnContextDestroy(mContext); |
| 104 | } |
| 105 | native void rsnContextSetSurface(int con, int w, int h, Surface sur); |
| 106 | synchronized void nContextSetSurface(int w, int h, Surface sur) { |
| 107 | rsnContextSetSurface(mContext, w, h, sur); |
| 108 | } |
| 109 | native void rsnContextSetPriority(int con, int p); |
| 110 | synchronized void nContextSetPriority(int p) { |
| 111 | rsnContextSetPriority(mContext, p); |
| 112 | } |
| 113 | native void rsnContextDump(int con, int bits); |
| 114 | synchronized void nContextDump(int bits) { |
| 115 | rsnContextDump(mContext, bits); |
| 116 | } |
| 117 | native void rsnContextFinish(int con); |
| 118 | synchronized void nContextFinish() { |
| 119 | rsnContextFinish(mContext); |
| 120 | } |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 121 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 122 | native void rsnContextBindRootScript(int con, int script); |
| 123 | synchronized void nContextBindRootScript(int script) { |
| 124 | rsnContextBindRootScript(mContext, script); |
| 125 | } |
| 126 | native void rsnContextBindSampler(int con, int sampler, int slot); |
| 127 | synchronized void nContextBindSampler(int sampler, int slot) { |
| 128 | rsnContextBindSampler(mContext, sampler, slot); |
| 129 | } |
| 130 | native void rsnContextBindProgramStore(int con, int pfs); |
| 131 | synchronized void nContextBindProgramStore(int pfs) { |
| 132 | rsnContextBindProgramStore(mContext, pfs); |
| 133 | } |
| 134 | native void rsnContextBindProgramFragment(int con, int pf); |
| 135 | synchronized void nContextBindProgramFragment(int pf) { |
| 136 | rsnContextBindProgramFragment(mContext, pf); |
| 137 | } |
| 138 | native void rsnContextBindProgramVertex(int con, int pv); |
| 139 | synchronized void nContextBindProgramVertex(int pv) { |
| 140 | rsnContextBindProgramVertex(mContext, pv); |
| 141 | } |
| 142 | native void rsnContextBindProgramRaster(int con, int pr); |
| 143 | synchronized void nContextBindProgramRaster(int pr) { |
| 144 | rsnContextBindProgramRaster(mContext, pr); |
| 145 | } |
| 146 | native void rsnContextPause(int con); |
| 147 | synchronized void nContextPause() { |
| 148 | rsnContextPause(mContext); |
| 149 | } |
| 150 | native void rsnContextResume(int con); |
| 151 | synchronized void nContextResume() { |
| 152 | rsnContextResume(mContext); |
| 153 | } |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 154 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 155 | native void rsnAssignName(int con, int obj, byte[] name); |
| 156 | synchronized void nAssignName(int obj, byte[] name) { |
| 157 | rsnAssignName(mContext, obj, name); |
| 158 | } |
| 159 | native String rsnGetName(int con, int obj); |
| 160 | synchronized String nGetName(int obj) { |
| 161 | return rsnGetName(mContext, obj); |
| 162 | } |
| 163 | native void rsnObjDestroy(int con, int id); |
| 164 | synchronized void nObjDestroy(int id) { |
| 165 | rsnObjDestroy(mContext, id); |
| 166 | } |
| Jason Sams | fe08d99 | 2009-05-27 14:45:32 -0700 | [diff] [blame] | 167 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 168 | native int rsnElementCreate(int con, int type, int kind, boolean norm, int vecSize); |
| 169 | synchronized int nElementCreate(int type, int kind, boolean norm, int vecSize) { |
| 170 | return rsnElementCreate(mContext, type, kind, norm, vecSize); |
| 171 | } |
| Jason Sams | 70d4e50 | 2010-09-02 17:35:23 -0700 | [diff] [blame] | 172 | native int rsnElementCreate2(int con, int[] elements, String[] names, int[] arraySizes); |
| 173 | synchronized int nElementCreate2(int[] elements, String[] names, int[] arraySizes) { |
| 174 | return rsnElementCreate2(mContext, elements, names, arraySizes); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 175 | } |
| 176 | native void rsnElementGetNativeData(int con, int id, int[] elementData); |
| 177 | synchronized void nElementGetNativeData(int id, int[] elementData) { |
| 178 | rsnElementGetNativeData(mContext, id, elementData); |
| 179 | } |
| 180 | native void rsnElementGetSubElements(int con, int id, int[] IDs, String[] names); |
| 181 | synchronized void nElementGetSubElements(int id, int[] IDs, String[] names) { |
| 182 | rsnElementGetSubElements(mContext, id, IDs, names); |
| 183 | } |
| Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 184 | |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 185 | native int rsnTypeCreate(int con, int eid, int x, int y, int z, boolean mips, boolean faces); |
| 186 | synchronized int nTypeCreate(int eid, int x, int y, int z, boolean mips, boolean faces) { |
| 187 | return rsnTypeCreate(mContext, eid, x, y, z, mips, faces); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 188 | } |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 189 | native void rsnTypeGetNativeData(int con, int id, int[] typeData); |
| 190 | synchronized void nTypeGetNativeData(int id, int[] typeData) { |
| 191 | rsnTypeGetNativeData(mContext, id, typeData); |
| 192 | } |
| Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 193 | |
| Jason Sams | d4b23b5 | 2010-12-13 15:32:35 -0800 | [diff] [blame] | 194 | native int rsnAllocationCreateTyped(int con, int type, int mip, int usage); |
| 195 | synchronized int nAllocationCreateTyped(int type, int mip, int usage) { |
| 196 | return rsnAllocationCreateTyped(mContext, type, mip, usage); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 197 | } |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 198 | native int rsnAllocationCreateFromBitmap(int con, int type, int mip, Bitmap bmp, int usage); |
| 199 | synchronized int nAllocationCreateFromBitmap(int type, int mip, Bitmap bmp, int usage) { |
| 200 | return rsnAllocationCreateFromBitmap(mContext, type, mip, bmp, usage); |
| Alex Sakhartchouk | 26ae390 | 2010-10-11 12:35:15 -0700 | [diff] [blame] | 201 | } |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 202 | native int rsnAllocationCubeCreateFromBitmap(int con, int type, int mip, Bitmap bmp, int usage); |
| 203 | synchronized int nAllocationCubeCreateFromBitmap(int type, int mip, Bitmap bmp, int usage) { |
| 204 | return rsnAllocationCubeCreateFromBitmap(mContext, type, mip, bmp, usage); |
| Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 205 | } |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 206 | native int rsnAllocationCreateBitmapRef(int con, int type, Bitmap bmp); |
| 207 | synchronized int nAllocationCreateBitmapRef(int type, Bitmap bmp) { |
| 208 | return rsnAllocationCreateBitmapRef(mContext, type, bmp); |
| 209 | } |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 210 | native int rsnAllocationCreateFromAssetStream(int con, int mips, int assetStream, int usage); |
| 211 | synchronized int nAllocationCreateFromAssetStream(int mips, int assetStream, int usage) { |
| 212 | return rsnAllocationCreateFromAssetStream(mContext, mips, assetStream, usage); |
| 213 | } |
| 214 | |
| Jason Sams | 4ef6650 | 2010-12-10 16:03:15 -0800 | [diff] [blame] | 215 | native void rsnAllocationCopyToBitmap(int con, int alloc, Bitmap bmp); |
| 216 | synchronized void nAllocationCopyToBitmap(int alloc, Bitmap bmp) { |
| 217 | rsnAllocationCopyToBitmap(mContext, alloc, bmp); |
| 218 | } |
| 219 | |
| 220 | |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 221 | native void rsnAllocationSyncAll(int con, int alloc, int src); |
| 222 | synchronized void nAllocationSyncAll(int alloc, int src) { |
| 223 | rsnAllocationSyncAll(mContext, alloc, src); |
| 224 | } |
| Jason Sams | 4ef6650 | 2010-12-10 16:03:15 -0800 | [diff] [blame] | 225 | native void rsnAllocationCopyFromBitmap(int con, int alloc, Bitmap bmp); |
| 226 | synchronized void nAllocationCopyFromBitmap(int alloc, Bitmap bmp) { |
| 227 | rsnAllocationCopyFromBitmap(mContext, alloc, bmp); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 228 | } |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 229 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 230 | native void rsnAllocationUploadToTexture(int con, int alloc, boolean genMips, int baseMioLevel); |
| 231 | synchronized void nAllocationUploadToTexture(int alloc, boolean genMips, int baseMioLevel) { |
| 232 | rsnAllocationUploadToTexture(mContext, alloc, genMips, baseMioLevel); |
| 233 | } |
| 234 | native void rsnAllocationUploadToBufferObject(int con, int alloc); |
| 235 | synchronized void nAllocationUploadToBufferObject(int alloc) { |
| 236 | rsnAllocationUploadToBufferObject(mContext, alloc); |
| 237 | } |
| Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 238 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 239 | native void rsnAllocationSubData1D(int con, int id, int off, int count, int[] d, int sizeBytes); |
| 240 | synchronized void nAllocationSubData1D(int id, int off, int count, int[] d, int sizeBytes) { |
| 241 | rsnAllocationSubData1D(mContext, id, off, count, d, sizeBytes); |
| 242 | } |
| 243 | native void rsnAllocationSubData1D(int con, int id, int off, int count, short[] d, int sizeBytes); |
| 244 | synchronized void nAllocationSubData1D(int id, int off, int count, short[] d, int sizeBytes) { |
| 245 | rsnAllocationSubData1D(mContext, id, off, count, d, sizeBytes); |
| 246 | } |
| 247 | native void rsnAllocationSubData1D(int con, int id, int off, int count, byte[] d, int sizeBytes); |
| 248 | synchronized void nAllocationSubData1D(int id, int off, int count, byte[] d, int sizeBytes) { |
| 249 | rsnAllocationSubData1D(mContext, id, off, count, d, sizeBytes); |
| 250 | } |
| Jason Sams | 49bdaf0 | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 251 | native void rsnAllocationSubElementData1D(int con, int id, int xoff, int compIdx, byte[] d, int sizeBytes); |
| 252 | synchronized void nAllocationSubElementData1D(int id, int xoff, int compIdx, byte[] d, int sizeBytes) { |
| 253 | rsnAllocationSubElementData1D(mContext, id, xoff, compIdx, d, sizeBytes); |
| 254 | } |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 255 | native void rsnAllocationSubData1D(int con, int id, int off, int count, float[] d, int sizeBytes); |
| 256 | synchronized void nAllocationSubData1D(int id, int off, int count, float[] d, int sizeBytes) { |
| 257 | rsnAllocationSubData1D(mContext, id, off, count, d, sizeBytes); |
| 258 | } |
| Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 259 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 260 | native void rsnAllocationSubData2D(int con, int id, int xoff, int yoff, int w, int h, int[] d, int sizeBytes); |
| 261 | synchronized void nAllocationSubData2D(int id, int xoff, int yoff, int w, int h, int[] d, int sizeBytes) { |
| 262 | rsnAllocationSubData2D(mContext, id, xoff, yoff, w, h, d, sizeBytes); |
| 263 | } |
| 264 | native void rsnAllocationSubData2D(int con, int id, int xoff, int yoff, int w, int h, float[] d, int sizeBytes); |
| 265 | synchronized void nAllocationSubData2D(int id, int xoff, int yoff, int w, int h, float[] d, int sizeBytes) { |
| 266 | rsnAllocationSubData2D(mContext, id, xoff, yoff, w, h, d, sizeBytes); |
| 267 | } |
| 268 | native void rsnAllocationRead(int con, int id, int[] d); |
| 269 | synchronized void nAllocationRead(int id, int[] d) { |
| 270 | rsnAllocationRead(mContext, id, d); |
| 271 | } |
| 272 | native void rsnAllocationRead(int con, int id, float[] d); |
| 273 | synchronized void nAllocationRead(int id, float[] d) { |
| 274 | rsnAllocationRead(mContext, id, d); |
| 275 | } |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 276 | native int rsnAllocationGetType(int con, int id); |
| 277 | synchronized int nAllocationGetType(int id) { |
| 278 | return rsnAllocationGetType(mContext, id); |
| 279 | } |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 280 | |
| Jason Sams | 5edc608 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 281 | native void rsnAllocationResize1D(int con, int id, int dimX); |
| 282 | synchronized void nAllocationResize1D(int id, int dimX) { |
| 283 | rsnAllocationResize1D(mContext, id, dimX); |
| 284 | } |
| 285 | native void rsnAllocationResize2D(int con, int id, int dimX, int dimY); |
| 286 | synchronized void nAllocationResize2D(int id, int dimX, int dimY) { |
| 287 | rsnAllocationResize2D(mContext, id, dimX, dimY); |
| 288 | } |
| 289 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 290 | native int rsnFileA3DCreateFromAssetStream(int con, int assetStream); |
| 291 | synchronized int nFileA3DCreateFromAssetStream(int assetStream) { |
| 292 | return rsnFileA3DCreateFromAssetStream(mContext, assetStream); |
| 293 | } |
| 294 | native int rsnFileA3DGetNumIndexEntries(int con, int fileA3D); |
| 295 | synchronized int nFileA3DGetNumIndexEntries(int fileA3D) { |
| 296 | return rsnFileA3DGetNumIndexEntries(mContext, fileA3D); |
| 297 | } |
| 298 | native void rsnFileA3DGetIndexEntries(int con, int fileA3D, int numEntries, int[] IDs, String[] names); |
| 299 | synchronized void nFileA3DGetIndexEntries(int fileA3D, int numEntries, int[] IDs, String[] names) { |
| 300 | rsnFileA3DGetIndexEntries(mContext, fileA3D, numEntries, IDs, names); |
| 301 | } |
| 302 | native int rsnFileA3DGetEntryByIndex(int con, int fileA3D, int index); |
| 303 | synchronized int nFileA3DGetEntryByIndex(int fileA3D, int index) { |
| 304 | return rsnFileA3DGetEntryByIndex(mContext, fileA3D, index); |
| 305 | } |
| Jason Sams | bd1c3ad | 2009-08-03 16:03:08 -0700 | [diff] [blame] | 306 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 307 | native int rsnFontCreateFromFile(int con, String fileName, int size, int dpi); |
| 308 | synchronized int nFontCreateFromFile(String fileName, int size, int dpi) { |
| 309 | return rsnFontCreateFromFile(mContext, fileName, size, dpi); |
| 310 | } |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 311 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 312 | native void rsnAdapter1DBindAllocation(int con, int ad, int alloc); |
| 313 | synchronized void nAdapter1DBindAllocation(int ad, int alloc) { |
| 314 | rsnAdapter1DBindAllocation(mContext, ad, alloc); |
| 315 | } |
| 316 | native void rsnAdapter1DSetConstraint(int con, int ad, int dim, int value); |
| 317 | synchronized void nAdapter1DSetConstraint(int ad, int dim, int value) { |
| 318 | rsnAdapter1DSetConstraint(mContext, ad, dim, value); |
| 319 | } |
| 320 | native void rsnAdapter1DData(int con, int ad, int[] d); |
| 321 | synchronized void nAdapter1DData(int ad, int[] d) { |
| 322 | rsnAdapter1DData(mContext, ad, d); |
| 323 | } |
| 324 | native void rsnAdapter1DData(int con, int ad, float[] d); |
| 325 | synchronized void nAdapter1DData(int ad, float[] d) { |
| 326 | rsnAdapter1DData(mContext, ad, d); |
| 327 | } |
| 328 | native void rsnAdapter1DSubData(int con, int ad, int off, int count, int[] d); |
| 329 | synchronized void nAdapter1DSubData(int ad, int off, int count, int[] d) { |
| 330 | rsnAdapter1DSubData(mContext, ad, off, count, d); |
| 331 | } |
| 332 | native void rsnAdapter1DSubData(int con, int ad, int off, int count, float[] d); |
| 333 | synchronized void nAdapter1DSubData(int ad, int off, int count, float[] d) { |
| 334 | rsnAdapter1DSubData(mContext, ad, off, count, d); |
| 335 | } |
| 336 | native int rsnAdapter1DCreate(int con); |
| 337 | synchronized int nAdapter1DCreate() { |
| 338 | return rsnAdapter1DCreate(mContext); |
| 339 | } |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 340 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 341 | native void rsnAdapter2DBindAllocation(int con, int ad, int alloc); |
| 342 | synchronized void nAdapter2DBindAllocation(int ad, int alloc) { |
| 343 | rsnAdapter2DBindAllocation(mContext, ad, alloc); |
| 344 | } |
| 345 | native void rsnAdapter2DSetConstraint(int con, int ad, int dim, int value); |
| 346 | synchronized void nAdapter2DSetConstraint(int ad, int dim, int value) { |
| 347 | rsnAdapter2DSetConstraint(mContext, ad, dim, value); |
| 348 | } |
| 349 | native void rsnAdapter2DData(int con, int ad, int[] d); |
| 350 | synchronized void nAdapter2DData(int ad, int[] d) { |
| 351 | rsnAdapter2DData(mContext, ad, d); |
| 352 | } |
| 353 | native void rsnAdapter2DData(int con, int ad, float[] d); |
| 354 | synchronized void nAdapter2DData(int ad, float[] d) { |
| 355 | rsnAdapter2DData(mContext, ad, d); |
| 356 | } |
| 357 | native void rsnAdapter2DSubData(int con, int ad, int xoff, int yoff, int w, int h, int[] d); |
| 358 | synchronized void nAdapter2DSubData(int ad, int xoff, int yoff, int w, int h, int[] d) { |
| 359 | rsnAdapter2DSubData(mContext, ad, xoff, yoff, w, h, d); |
| 360 | } |
| 361 | native void rsnAdapter2DSubData(int con, int ad, int xoff, int yoff, int w, int h, float[] d); |
| 362 | synchronized void nAdapter2DSubData(int ad, int xoff, int yoff, int w, int h, float[] d) { |
| 363 | rsnAdapter2DSubData(mContext, ad, xoff, yoff, w, h, d); |
| 364 | } |
| 365 | native int rsnAdapter2DCreate(int con); |
| 366 | synchronized int nAdapter2DCreate() { |
| 367 | return rsnAdapter2DCreate(mContext); |
| 368 | } |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 369 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 370 | native void rsnScriptBindAllocation(int con, int script, int alloc, int slot); |
| 371 | synchronized void nScriptBindAllocation(int script, int alloc, int slot) { |
| 372 | rsnScriptBindAllocation(mContext, script, alloc, slot); |
| 373 | } |
| 374 | native void rsnScriptSetTimeZone(int con, int script, byte[] timeZone); |
| 375 | synchronized void nScriptSetTimeZone(int script, byte[] timeZone) { |
| 376 | rsnScriptSetTimeZone(mContext, script, timeZone); |
| 377 | } |
| 378 | native void rsnScriptInvoke(int con, int id, int slot); |
| 379 | synchronized void nScriptInvoke(int id, int slot) { |
| 380 | rsnScriptInvoke(mContext, id, slot); |
| 381 | } |
| 382 | native void rsnScriptInvokeV(int con, int id, int slot, byte[] params); |
| 383 | synchronized void nScriptInvokeV(int id, int slot, byte[] params) { |
| 384 | rsnScriptInvokeV(mContext, id, slot, params); |
| 385 | } |
| 386 | native void rsnScriptSetVarI(int con, int id, int slot, int val); |
| 387 | synchronized void nScriptSetVarI(int id, int slot, int val) { |
| 388 | rsnScriptSetVarI(mContext, id, slot, val); |
| 389 | } |
| Stephen Hines | 031ec58c | 2010-10-11 10:54:21 -0700 | [diff] [blame] | 390 | native void rsnScriptSetVarJ(int con, int id, int slot, long val); |
| 391 | synchronized void nScriptSetVarJ(int id, int slot, long val) { |
| 392 | rsnScriptSetVarJ(mContext, id, slot, val); |
| 393 | } |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 394 | native void rsnScriptSetVarF(int con, int id, int slot, float val); |
| 395 | synchronized void nScriptSetVarF(int id, int slot, float val) { |
| 396 | rsnScriptSetVarF(mContext, id, slot, val); |
| 397 | } |
| Stephen Hines | ca54ec3 | 2010-09-20 17:20:30 -0700 | [diff] [blame] | 398 | native void rsnScriptSetVarD(int con, int id, int slot, double val); |
| 399 | synchronized void nScriptSetVarD(int id, int slot, double val) { |
| 400 | rsnScriptSetVarD(mContext, id, slot, val); |
| 401 | } |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 402 | native void rsnScriptSetVarV(int con, int id, int slot, byte[] val); |
| 403 | synchronized void nScriptSetVarV(int id, int slot, byte[] val) { |
| 404 | rsnScriptSetVarV(mContext, id, slot, val); |
| 405 | } |
| Jason Sams | 6f4cf0b | 2010-11-16 17:37:02 -0800 | [diff] [blame] | 406 | native void rsnScriptSetVarObj(int con, int id, int slot, int val); |
| 407 | synchronized void nScriptSetVarObj(int id, int slot, int val) { |
| 408 | rsnScriptSetVarObj(mContext, id, slot, val); |
| 409 | } |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 410 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 411 | native void rsnScriptCBegin(int con); |
| 412 | synchronized void nScriptCBegin() { |
| 413 | rsnScriptCBegin(mContext); |
| 414 | } |
| 415 | native void rsnScriptCSetScript(int con, byte[] script, int offset, int length); |
| 416 | synchronized void nScriptCSetScript(byte[] script, int offset, int length) { |
| 417 | rsnScriptCSetScript(mContext, script, offset, length); |
| 418 | } |
| Shih-wei Liao | a914f34 | 2010-11-08 01:33:59 -0800 | [diff] [blame] | 419 | native int rsnScriptCCreate(int con, String val); |
| 420 | synchronized int nScriptCCreate(String val) { |
| 421 | return rsnScriptCCreate(mContext, val); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 422 | } |
| Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 423 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 424 | native void rsnSamplerBegin(int con); |
| 425 | synchronized void nSamplerBegin() { |
| 426 | rsnSamplerBegin(mContext); |
| 427 | } |
| 428 | native void rsnSamplerSet(int con, int param, int value); |
| 429 | synchronized void nSamplerSet(int param, int value) { |
| 430 | rsnSamplerSet(mContext, param, value); |
| 431 | } |
| Alex Sakhartchouk | f5b3510 | 2010-09-30 11:36:37 -0700 | [diff] [blame] | 432 | native void rsnSamplerSet2(int con, int param, float value); |
| 433 | synchronized void nSamplerSet2(int param, float value) { |
| 434 | rsnSamplerSet2(mContext, param, value); |
| 435 | } |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 436 | native int rsnSamplerCreate(int con); |
| 437 | synchronized int nSamplerCreate() { |
| 438 | return rsnSamplerCreate(mContext); |
| 439 | } |
| Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 440 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 441 | native void rsnProgramStoreBegin(int con, int in, int out); |
| 442 | synchronized void nProgramStoreBegin(int in, int out) { |
| 443 | rsnProgramStoreBegin(mContext, in, out); |
| 444 | } |
| 445 | native void rsnProgramStoreDepthFunc(int con, int func); |
| 446 | synchronized void nProgramStoreDepthFunc(int func) { |
| 447 | rsnProgramStoreDepthFunc(mContext, func); |
| 448 | } |
| 449 | native void rsnProgramStoreDepthMask(int con, boolean enable); |
| 450 | synchronized void nProgramStoreDepthMask(boolean enable) { |
| 451 | rsnProgramStoreDepthMask(mContext, enable); |
| 452 | } |
| 453 | native void rsnProgramStoreColorMask(int con, boolean r, boolean g, boolean b, boolean a); |
| 454 | synchronized void nProgramStoreColorMask(boolean r, boolean g, boolean b, boolean a) { |
| 455 | rsnProgramStoreColorMask(mContext, r, g, b, a); |
| 456 | } |
| 457 | native void rsnProgramStoreBlendFunc(int con, int src, int dst); |
| 458 | synchronized void nProgramStoreBlendFunc(int src, int dst) { |
| 459 | rsnProgramStoreBlendFunc(mContext, src, dst); |
| 460 | } |
| 461 | native void rsnProgramStoreDither(int con, boolean enable); |
| 462 | synchronized void nProgramStoreDither(boolean enable) { |
| 463 | rsnProgramStoreDither(mContext, enable); |
| 464 | } |
| 465 | native int rsnProgramStoreCreate(int con); |
| 466 | synchronized int nProgramStoreCreate() { |
| 467 | return rsnProgramStoreCreate(mContext); |
| 468 | } |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 469 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 470 | native int rsnProgramRasterCreate(int con, boolean pointSmooth, boolean lineSmooth, boolean pointSprite); |
| 471 | synchronized int nProgramRasterCreate(boolean pointSmooth, boolean lineSmooth, boolean pointSprite) { |
| 472 | return rsnProgramRasterCreate(mContext, pointSmooth, lineSmooth, pointSprite); |
| 473 | } |
| 474 | native void rsnProgramRasterSetLineWidth(int con, int pr, float v); |
| 475 | synchronized void nProgramRasterSetLineWidth(int pr, float v) { |
| 476 | rsnProgramRasterSetLineWidth(mContext, pr, v); |
| 477 | } |
| 478 | native void rsnProgramRasterSetCullMode(int con, int pr, int mode); |
| 479 | synchronized void nProgramRasterSetCullMode(int pr, int mode) { |
| 480 | rsnProgramRasterSetCullMode(mContext, pr, mode); |
| 481 | } |
| Jason Sams | 1fe9b8c | 2009-06-11 14:46:10 -0700 | [diff] [blame] | 482 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 483 | native void rsnProgramBindConstants(int con, int pv, int slot, int mID); |
| 484 | synchronized void nProgramBindConstants(int pv, int slot, int mID) { |
| 485 | rsnProgramBindConstants(mContext, pv, slot, mID); |
| 486 | } |
| 487 | native void rsnProgramBindTexture(int con, int vpf, int slot, int a); |
| 488 | synchronized void nProgramBindTexture(int vpf, int slot, int a) { |
| 489 | rsnProgramBindTexture(mContext, vpf, slot, a); |
| 490 | } |
| 491 | native void rsnProgramBindSampler(int con, int vpf, int slot, int s); |
| 492 | synchronized void nProgramBindSampler(int vpf, int slot, int s) { |
| 493 | rsnProgramBindSampler(mContext, vpf, slot, s); |
| 494 | } |
| Alex Sakhartchouk | b89aaac | 2010-09-23 16:16:33 -0700 | [diff] [blame] | 495 | native int rsnProgramFragmentCreate(int con, String shader, int[] params); |
| 496 | synchronized int nProgramFragmentCreate(String shader, int[] params) { |
| 497 | return rsnProgramFragmentCreate(mContext, shader, params); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 498 | } |
| Alex Sakhartchouk | b89aaac | 2010-09-23 16:16:33 -0700 | [diff] [blame] | 499 | native int rsnProgramVertexCreate(int con, String shader, int[] params); |
| 500 | synchronized int nProgramVertexCreate(String shader, int[] params) { |
| 501 | return rsnProgramVertexCreate(mContext, shader, params); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 502 | } |
| Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 503 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 504 | native int rsnMeshCreate(int con, int vtxCount, int indexCount); |
| 505 | synchronized int nMeshCreate(int vtxCount, int indexCount) { |
| 506 | return rsnMeshCreate(mContext, vtxCount, indexCount); |
| 507 | } |
| 508 | native void rsnMeshBindVertex(int con, int id, int alloc, int slot); |
| 509 | synchronized void nMeshBindVertex(int id, int alloc, int slot) { |
| 510 | rsnMeshBindVertex(mContext, id, alloc, slot); |
| 511 | } |
| 512 | native void rsnMeshBindIndex(int con, int id, int alloc, int prim, int slot); |
| 513 | synchronized void nMeshBindIndex(int id, int alloc, int prim, int slot) { |
| 514 | rsnMeshBindIndex(mContext, id, alloc, prim, slot); |
| 515 | } |
| Alex Sakhartchouk | 9d71e21 | 2010-11-08 15:10:52 -0800 | [diff] [blame] | 516 | native void rsnMeshInitVertexAttribs(int con, int id); |
| 517 | synchronized void nMeshInitVertexAttribs(int id) { |
| 518 | rsnMeshInitVertexAttribs(mContext, id); |
| 519 | } |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 520 | native int rsnMeshGetVertexBufferCount(int con, int id); |
| 521 | synchronized int nMeshGetVertexBufferCount(int id) { |
| 522 | return rsnMeshGetVertexBufferCount(mContext, id); |
| 523 | } |
| 524 | native int rsnMeshGetIndexCount(int con, int id); |
| 525 | synchronized int nMeshGetIndexCount(int id) { |
| 526 | return rsnMeshGetIndexCount(mContext, id); |
| 527 | } |
| 528 | native void rsnMeshGetVertices(int con, int id, int[] vtxIds, int vtxIdCount); |
| 529 | synchronized void nMeshGetVertices(int id, int[] vtxIds, int vtxIdCount) { |
| 530 | rsnMeshGetVertices(mContext, id, vtxIds, vtxIdCount); |
| 531 | } |
| 532 | native void rsnMeshGetIndices(int con, int id, int[] idxIds, int[] primitives, int vtxIdCount); |
| 533 | synchronized void nMeshGetIndices(int id, int[] idxIds, int[] primitives, int vtxIdCount) { |
| 534 | rsnMeshGetIndices(mContext, id, idxIds, primitives, vtxIdCount); |
| 535 | } |
| 536 | |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 537 | |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 538 | int mDev; |
| 539 | int mContext; |
| Romain Guy | 650a3eb | 2009-08-31 14:06:43 -0700 | [diff] [blame] | 540 | @SuppressWarnings({"FieldCanBeLocal"}) |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 541 | MessageThread mMessageThread; |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 542 | |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 543 | Element mElement_U8; |
| 544 | Element mElement_I8; |
| 545 | Element mElement_U16; |
| 546 | Element mElement_I16; |
| 547 | Element mElement_U32; |
| 548 | Element mElement_I32; |
| Stephen Hines | 52d8363 | 2010-10-11 16:10:42 -0700 | [diff] [blame] | 549 | Element mElement_U64; |
| Stephen Hines | ef1dac2 | 2010-10-01 15:39:33 -0700 | [diff] [blame] | 550 | Element mElement_I64; |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 551 | Element mElement_F32; |
| Stephen Hines | 02f41705 | 2010-09-30 15:19:22 -0700 | [diff] [blame] | 552 | Element mElement_F64; |
| Jason Sams | f110d4b | 2010-06-21 17:42:41 -0700 | [diff] [blame] | 553 | Element mElement_BOOLEAN; |
| Jason Sams | 3c0dfba | 2009-09-27 17:50:38 -0700 | [diff] [blame] | 554 | |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 555 | Element mElement_ELEMENT; |
| 556 | Element mElement_TYPE; |
| 557 | Element mElement_ALLOCATION; |
| 558 | Element mElement_SAMPLER; |
| 559 | Element mElement_SCRIPT; |
| 560 | Element mElement_MESH; |
| 561 | Element mElement_PROGRAM_FRAGMENT; |
| 562 | Element mElement_PROGRAM_VERTEX; |
| 563 | Element mElement_PROGRAM_RASTER; |
| 564 | Element mElement_PROGRAM_STORE; |
| Jason Sams | a70f416 | 2010-03-26 15:33:42 -0700 | [diff] [blame] | 565 | |
| Jason Sams | 3c0dfba | 2009-09-27 17:50:38 -0700 | [diff] [blame] | 566 | Element mElement_A_8; |
| 567 | Element mElement_RGB_565; |
| 568 | Element mElement_RGB_888; |
| 569 | Element mElement_RGBA_5551; |
| 570 | Element mElement_RGBA_4444; |
| 571 | Element mElement_RGBA_8888; |
| 572 | |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 573 | Element mElement_FLOAT_2; |
| 574 | Element mElement_FLOAT_3; |
| 575 | Element mElement_FLOAT_4; |
| 576 | Element mElement_UCHAR_4; |
| Jason Sams | 7d787b4 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 577 | |
| Jason Sams | 1d45c47 | 2010-08-25 14:31:48 -0700 | [diff] [blame] | 578 | Element mElement_MATRIX_4X4; |
| 579 | Element mElement_MATRIX_3X3; |
| 580 | Element mElement_MATRIX_2X2; |
| 581 | |
| Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 582 | Sampler mSampler_CLAMP_NEAREST; |
| 583 | Sampler mSampler_CLAMP_LINEAR; |
| 584 | Sampler mSampler_CLAMP_LINEAR_MIP_LINEAR; |
| 585 | Sampler mSampler_WRAP_NEAREST; |
| 586 | Sampler mSampler_WRAP_LINEAR; |
| 587 | Sampler mSampler_WRAP_LINEAR_MIP_LINEAR; |
| 588 | |
| Alex Sakhartchouk | d36f248 | 2010-08-24 11:37:33 -0700 | [diff] [blame] | 589 | ProgramStore mProgramStore_BLEND_NONE_DEPTH_TEST; |
| 590 | ProgramStore mProgramStore_BLEND_NONE_DEPTH_NO_DEPTH; |
| 591 | ProgramStore mProgramStore_BLEND_NONE_DEPTH_NO_TEST; |
| 592 | ProgramStore mProgramStore_BLEND_NONE_DEPTH_NO_WRITE; |
| 593 | ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_TEST; |
| 594 | ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_NO_DEPTH; |
| 595 | ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_NO_TEST; |
| 596 | ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_NO_WRITE; |
| 597 | ProgramStore mProgramStore_BLEND_ADD_DEPTH_TEST; |
| 598 | ProgramStore mProgramStore_BLEND_ADD_DEPTH_NO_DEPTH; |
| 599 | ProgramStore mProgramStore_BLEND_ADD_DEPTH_NO_TEST; |
| 600 | ProgramStore mProgramStore_BLEND_ADD_DEPTH_NO_WRITE; |
| Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame] | 601 | |
| Alex Sakhartchouk | d36f248 | 2010-08-24 11:37:33 -0700 | [diff] [blame] | 602 | ProgramRaster mProgramRaster_CULL_BACK; |
| 603 | ProgramRaster mProgramRaster_CULL_FRONT; |
| 604 | ProgramRaster mProgramRaster_CULL_NONE; |
| Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame] | 605 | |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 606 | /////////////////////////////////////////////////////////////////////////////////// |
| Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 607 | // |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 608 | |
| Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 609 | /** |
| 610 | * Base class application should derive from for handling RS messages |
| 611 | * comming from their scripts. When a script calls sendToClient the data |
| 612 | * fields will be filled in and then the run method called by a message |
| 613 | * handling thread. This will occur some time after sendToClient completes |
| 614 | * in the script. |
| 615 | * |
| 616 | */ |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 617 | public static class RSMessageHandler implements Runnable { |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 618 | protected int[] mData; |
| 619 | protected int mID; |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 620 | protected int mLength; |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 621 | public void run() { |
| 622 | } |
| 623 | } |
| Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 624 | /** |
| 625 | * If an application is expecting messages it should set this field to an |
| 626 | * instance of RSMessage. This instance will receive all the user messages |
| 627 | * sent from sendToClient by scripts from this context. |
| 628 | * |
| 629 | */ |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 630 | RSMessageHandler mMessageCallback = null; |
| 631 | |
| 632 | public void setMessageHandler(RSMessageHandler msg) { |
| 633 | mMessageCallback = msg; |
| 634 | } |
| 635 | public RSMessageHandler getMessageHandler() { |
| 636 | return mMessageCallback; |
| 637 | } |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 638 | |
| Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 639 | /** |
| 640 | * Runtime error base class. An application should derive from this class |
| 641 | * if it wishes to install an error handler. When errors occur at runtime |
| 642 | * the fields in this class will be filled and the run method called. |
| 643 | * |
| 644 | */ |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 645 | public static class RSErrorHandler implements Runnable { |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 646 | protected String mErrorMessage; |
| 647 | protected int mErrorNum; |
| 648 | public void run() { |
| 649 | } |
| 650 | } |
| Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 651 | |
| 652 | /** |
| 653 | * Application Error handler. All runtime errors will be dispatched to the |
| 654 | * instance of RSAsyncError set here. If this field is null a |
| 655 | * RSRuntimeException will instead be thrown with details about the error. |
| 656 | * This will cause program termaination. |
| 657 | * |
| 658 | */ |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 659 | RSErrorHandler mErrorCallback = null; |
| 660 | |
| 661 | public void setErrorHandler(RSErrorHandler msg) { |
| 662 | mErrorCallback = msg; |
| 663 | } |
| 664 | public RSErrorHandler getErrorHandler() { |
| 665 | return mErrorCallback; |
| 666 | } |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 667 | |
| Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 668 | /** |
| 669 | * RenderScript worker threads priority enumeration. The default value is |
| 670 | * NORMAL. Applications wishing to do background processing such as |
| 671 | * wallpapers should set their priority to LOW to avoid starving forground |
| 672 | * processes. |
| 673 | */ |
| Jason Sams | 7d787b4 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 674 | public enum Priority { |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 675 | // Remap these numbers to opaque... |
| Jason Sams | 7d787b4 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 676 | LOW (5), //ANDROID_PRIORITY_BACKGROUND + 5 |
| 677 | NORMAL (-4); //ANDROID_PRIORITY_DISPLAY |
| 678 | |
| 679 | int mID; |
| 680 | Priority(int id) { |
| 681 | mID = id; |
| 682 | } |
| 683 | } |
| 684 | |
| Jason Sams | 771bebb | 2009-12-07 12:40:12 -0800 | [diff] [blame] | 685 | void validate() { |
| 686 | if (mContext == 0) { |
| Jason Sams | c1d6210 | 2010-11-04 14:32:19 -0700 | [diff] [blame] | 687 | throw new RSInvalidStateException("Calling RS with no Context active."); |
| Jason Sams | 771bebb | 2009-12-07 12:40:12 -0800 | [diff] [blame] | 688 | } |
| 689 | } |
| 690 | |
| Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 691 | |
| 692 | /** |
| 693 | * Change the priority of the worker threads for this context. |
| 694 | * |
| 695 | * @param p New priority to be set. |
| 696 | */ |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 697 | public void setPriority(Priority p) { |
| Jason Sams | 5dbfe93 | 2010-01-27 14:41:43 -0800 | [diff] [blame] | 698 | validate(); |
| Jason Sams | 7d787b4 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 699 | nContextSetPriority(p.mID); |
| 700 | } |
| 701 | |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 702 | static class MessageThread extends Thread { |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 703 | RenderScript mRS; |
| 704 | boolean mRun = true; |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 705 | int[] mAuxData = new int[2]; |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 706 | |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 707 | static final int RS_MESSAGE_TO_CLIENT_NONE = 0; |
| 708 | static final int RS_MESSAGE_TO_CLIENT_EXCEPTION = 1; |
| 709 | static final int RS_MESSAGE_TO_CLIENT_RESIZE = 2; |
| 710 | static final int RS_MESSAGE_TO_CLIENT_ERROR = 3; |
| 711 | static final int RS_MESSAGE_TO_CLIENT_USER = 4; |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 712 | |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 713 | static final int RS_ERROR_FATAL_UNKNOWN = 0x1000; |
| Jason Sams | add9d96 | 2010-11-22 16:20:16 -0800 | [diff] [blame] | 714 | |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 715 | MessageThread(RenderScript rs) { |
| 716 | super("RSMessageThread"); |
| 717 | mRS = rs; |
| 718 | |
| 719 | } |
| 720 | |
| 721 | public void run() { |
| 722 | // This function is a temporary solution. The final solution will |
| 723 | // used typed allocations where the message id is the type indicator. |
| 724 | int[] rbuf = new int[16]; |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 725 | mRS.nContextInitToClient(mRS.mContext); |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 726 | while(mRun) { |
| Jason Sams | 1d45c47 | 2010-08-25 14:31:48 -0700 | [diff] [blame] | 727 | rbuf[0] = 0; |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 728 | int msg = mRS.nContextPeekMessage(mRS.mContext, mAuxData, true); |
| 729 | int size = mAuxData[1]; |
| 730 | int subID = mAuxData[0]; |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 731 | |
| 732 | if (msg == RS_MESSAGE_TO_CLIENT_USER) { |
| 733 | if ((size>>2) >= rbuf.length) { |
| 734 | rbuf = new int[(size + 3) >> 2]; |
| 735 | } |
| 736 | mRS.nContextGetUserMessage(mRS.mContext, rbuf); |
| 737 | |
| 738 | if(mRS.mMessageCallback != null) { |
| 739 | mRS.mMessageCallback.mData = rbuf; |
| 740 | mRS.mMessageCallback.mID = subID; |
| 741 | mRS.mMessageCallback.mLength = size; |
| 742 | mRS.mMessageCallback.run(); |
| Jason Sams | 1d45c47 | 2010-08-25 14:31:48 -0700 | [diff] [blame] | 743 | } else { |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 744 | 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] | 745 | } |
| Stephen Hines | ab98bb6 | 2010-09-24 14:38:30 -0700 | [diff] [blame] | 746 | continue; |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 747 | } |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 748 | |
| 749 | if (msg == RS_MESSAGE_TO_CLIENT_ERROR) { |
| 750 | String e = mRS.nContextGetErrorMessage(mRS.mContext); |
| 751 | |
| Jason Sams | add9d96 | 2010-11-22 16:20:16 -0800 | [diff] [blame] | 752 | if (subID >= RS_ERROR_FATAL_UNKNOWN) { |
| 753 | throw new RSRuntimeException("Fatal error " + subID + ", details: " + e); |
| 754 | } |
| 755 | |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 756 | if(mRS.mErrorCallback != null) { |
| 757 | mRS.mErrorCallback.mErrorMessage = e; |
| 758 | mRS.mErrorCallback.mErrorNum = subID; |
| 759 | mRS.mErrorCallback.run(); |
| 760 | } else { |
| 761 | //throw new RSRuntimeException("Received error num " + subID + ", details: " + e); |
| 762 | } |
| 763 | continue; |
| 764 | } |
| 765 | |
| 766 | // 2: teardown. |
| 767 | // But we want to avoid starving other threads during |
| 768 | // teardown by yielding until the next line in the destructor |
| 769 | // can execute to set mRun = false |
| 770 | try { |
| 771 | sleep(1, 0); |
| 772 | } catch(InterruptedException e) { |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 773 | } |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 774 | } |
| Jason Sams | 3bc47d4 | 2009-11-12 15:10:25 -0800 | [diff] [blame] | 775 | Log.d(LOG_TAG, "MessageThread exiting."); |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 776 | } |
| 777 | } |
| 778 | |
| Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 779 | RenderScript() { |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 780 | } |
| 781 | |
| Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 782 | /** |
| 783 | * Create a basic RenderScript context. |
| 784 | * |
| 785 | * |
| 786 | * @return RenderScript |
| 787 | */ |
| Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 788 | public static RenderScript create() { |
| 789 | RenderScript rs = new RenderScript(); |
| 790 | |
| 791 | rs.mDev = rs.nDeviceCreate(); |
| 792 | rs.mContext = rs.nContextCreate(rs.mDev, 0); |
| 793 | rs.mMessageThread = new MessageThread(rs); |
| 794 | rs.mMessageThread.start(); |
| Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 795 | return rs; |
| Jason Sams | efd9b6fb | 2009-11-03 13:58:36 -0800 | [diff] [blame] | 796 | } |
| 797 | |
| Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 798 | /** |
| 799 | * Print the currently available debugging information about the state of |
| 800 | * the RS context to the log. |
| 801 | * |
| Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 802 | */ |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 803 | public void contextDump() { |
| Jason Sams | 5dbfe93 | 2010-01-27 14:41:43 -0800 | [diff] [blame] | 804 | validate(); |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 805 | nContextDump(0); |
| Jason Sams | 715333b | 2009-11-17 17:26:46 -0800 | [diff] [blame] | 806 | } |
| 807 | |
| Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 808 | /** |
| 809 | * Wait for any commands in the fifo between the java bindings and native to |
| 810 | * be processed. |
| 811 | * |
| 812 | */ |
| Jason Sams | 96ed4cf | 2010-06-15 12:15:57 -0700 | [diff] [blame] | 813 | public void finish() { |
| 814 | nContextFinish(); |
| 815 | } |
| 816 | |
| Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 817 | /** |
| 818 | * Destroy this renderscript context. Once this function is called its no |
| 819 | * longer legal to use this or any objects created by this context. |
| 820 | * |
| 821 | */ |
| Jason Sams | f5b4596 | 2009-08-25 14:49:07 -0700 | [diff] [blame] | 822 | public void destroy() { |
| Jason Sams | 5dbfe93 | 2010-01-27 14:41:43 -0800 | [diff] [blame] | 823 | validate(); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 824 | nContextDeinitToClient(mContext); |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 825 | mMessageThread.mRun = false; |
| Jason Sams | a8bf942 | 2010-09-16 13:43:19 -0700 | [diff] [blame] | 826 | try { |
| 827 | mMessageThread.join(); |
| 828 | } catch(InterruptedException e) { |
| 829 | } |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 830 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 831 | nContextDestroy(); |
| Jason Sams | f5b4596 | 2009-08-25 14:49:07 -0700 | [diff] [blame] | 832 | mContext = 0; |
| 833 | |
| 834 | nDeviceDestroy(mDev); |
| 835 | mDev = 0; |
| 836 | } |
| Jason Sams | 02fb2cb | 2009-05-28 15:37:57 -0700 | [diff] [blame] | 837 | |
| Jason Sams | a9e7a05 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 838 | boolean isAlive() { |
| 839 | return mContext != 0; |
| 840 | } |
| 841 | |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 842 | int safeID(BaseObj o) { |
| Jason Sams | 6b9dec0 | 2009-09-23 16:38:37 -0700 | [diff] [blame] | 843 | if(o != null) { |
| Jason Sams | 06d69de | 2010-11-09 17:11:40 -0800 | [diff] [blame] | 844 | return o.getID(); |
| Jason Sams | d8e4161 | 2009-08-20 17:22:40 -0700 | [diff] [blame] | 845 | } |
| Jason Sams | 6b9dec0 | 2009-09-23 16:38:37 -0700 | [diff] [blame] | 846 | return 0; |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 847 | } |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 848 | } |