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