| 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 | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 41 | protected static final boolean DEBUG = false; |
| Romain Guy | 650a3eb | 2009-08-31 14:06:43 -0700 | [diff] [blame] | 42 | @SuppressWarnings({"UnusedDeclaration", "deprecation"}) |
| Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 43 | protected 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 | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 52 | protected static boolean sInitialized; |
| 53 | native protected 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 | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 68 | native void nInitElements(int a8, int rgba4444, int rgba8888, int rgb565); |
| 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 | 3eaa338e | 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 | 3b9c52a | 2010-10-14 17:48:46 -0700 | [diff] [blame] | 186 | native int rsnTypeCreate(int con, int eid, int[] dims, int[] vals); |
| 187 | synchronized int nTypeCreate(int eid, int[] dims, int[] vals) { |
| 188 | return rsnTypeCreate(mContext, eid, dims, vals); |
| 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 | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 195 | native int rsnAllocationCreateTyped(int con, int type); |
| 196 | synchronized int nAllocationCreateTyped(int type) { |
| 197 | return rsnAllocationCreateTyped(mContext, type); |
| 198 | } |
| Alex Sakhartchouk | 26ae390 | 2010-10-11 12:35:15 -0700 | [diff] [blame] | 199 | native void rsnAllocationUpdateFromBitmap(int con, int alloc, Bitmap bmp); |
| 200 | synchronized void nAllocationUpdateFromBitmap(int alloc, Bitmap bmp) { |
| 201 | rsnAllocationUpdateFromBitmap(mContext, alloc, bmp); |
| 202 | } |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 203 | native int rsnAllocationCreateFromBitmap(int con, int dstFmt, boolean genMips, Bitmap bmp); |
| 204 | synchronized int nAllocationCreateFromBitmap(int dstFmt, boolean genMips, Bitmap bmp) { |
| 205 | return rsnAllocationCreateFromBitmap(mContext, dstFmt, genMips, bmp); |
| 206 | } |
| Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame^] | 207 | native int rsnAllocationCubeCreateFromBitmap(int con, int dstFmt, boolean genMips, Bitmap bmp); |
| 208 | synchronized int nAllocationCubeCreateFromBitmap(int dstFmt, boolean genMips, Bitmap bmp) { |
| 209 | return rsnAllocationCubeCreateFromBitmap(mContext, dstFmt, genMips, bmp); |
| 210 | } |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 211 | native int rsnAllocationCreateBitmapRef(int con, int type, Bitmap bmp); |
| 212 | synchronized int nAllocationCreateBitmapRef(int type, Bitmap bmp) { |
| 213 | return rsnAllocationCreateBitmapRef(mContext, type, bmp); |
| 214 | } |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 215 | native int rsnAllocationCreateFromAssetStream(int con, int dstFmt, boolean genMips, int assetStream); |
| 216 | synchronized int nAllocationCreateFromAssetStream(int dstFmt, boolean genMips, int assetStream) { |
| 217 | return rsnAllocationCreateFromAssetStream(mContext, dstFmt, genMips, assetStream); |
| 218 | } |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 219 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 220 | native void rsnAllocationUploadToTexture(int con, int alloc, boolean genMips, int baseMioLevel); |
| 221 | synchronized void nAllocationUploadToTexture(int alloc, boolean genMips, int baseMioLevel) { |
| 222 | rsnAllocationUploadToTexture(mContext, alloc, genMips, baseMioLevel); |
| 223 | } |
| 224 | native void rsnAllocationUploadToBufferObject(int con, int alloc); |
| 225 | synchronized void nAllocationUploadToBufferObject(int alloc) { |
| 226 | rsnAllocationUploadToBufferObject(mContext, alloc); |
| 227 | } |
| Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 228 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 229 | native void rsnAllocationSubData1D(int con, int id, int off, int count, int[] d, int sizeBytes); |
| 230 | synchronized void nAllocationSubData1D(int id, int off, int count, int[] d, int sizeBytes) { |
| 231 | rsnAllocationSubData1D(mContext, id, off, count, d, sizeBytes); |
| 232 | } |
| 233 | native void rsnAllocationSubData1D(int con, int id, int off, int count, short[] d, int sizeBytes); |
| 234 | synchronized void nAllocationSubData1D(int id, int off, int count, short[] d, int sizeBytes) { |
| 235 | rsnAllocationSubData1D(mContext, id, off, count, d, sizeBytes); |
| 236 | } |
| 237 | native void rsnAllocationSubData1D(int con, int id, int off, int count, byte[] d, int sizeBytes); |
| 238 | synchronized void nAllocationSubData1D(int id, int off, int count, byte[] d, int sizeBytes) { |
| 239 | rsnAllocationSubData1D(mContext, id, off, count, d, sizeBytes); |
| 240 | } |
| Jason Sams | 49bdaf0 | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 241 | native void rsnAllocationSubElementData1D(int con, int id, int xoff, int compIdx, byte[] d, int sizeBytes); |
| 242 | synchronized void nAllocationSubElementData1D(int id, int xoff, int compIdx, byte[] d, int sizeBytes) { |
| 243 | rsnAllocationSubElementData1D(mContext, id, xoff, compIdx, d, sizeBytes); |
| 244 | } |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 245 | native void rsnAllocationSubData1D(int con, int id, int off, int count, float[] d, int sizeBytes); |
| 246 | synchronized void nAllocationSubData1D(int id, int off, int count, float[] d, int sizeBytes) { |
| 247 | rsnAllocationSubData1D(mContext, id, off, count, d, sizeBytes); |
| 248 | } |
| Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 249 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 250 | native void rsnAllocationSubData2D(int con, int id, int xoff, int yoff, int w, int h, int[] d, int sizeBytes); |
| 251 | synchronized void nAllocationSubData2D(int id, int xoff, int yoff, int w, int h, int[] d, int sizeBytes) { |
| 252 | rsnAllocationSubData2D(mContext, id, xoff, yoff, w, h, d, sizeBytes); |
| 253 | } |
| 254 | native void rsnAllocationSubData2D(int con, int id, int xoff, int yoff, int w, int h, float[] d, int sizeBytes); |
| 255 | synchronized void nAllocationSubData2D(int id, int xoff, int yoff, int w, int h, float[] d, int sizeBytes) { |
| 256 | rsnAllocationSubData2D(mContext, id, xoff, yoff, w, h, d, sizeBytes); |
| 257 | } |
| 258 | native void rsnAllocationRead(int con, int id, int[] d); |
| 259 | synchronized void nAllocationRead(int id, int[] d) { |
| 260 | rsnAllocationRead(mContext, id, d); |
| 261 | } |
| 262 | native void rsnAllocationRead(int con, int id, float[] d); |
| 263 | synchronized void nAllocationRead(int id, float[] d) { |
| 264 | rsnAllocationRead(mContext, id, d); |
| 265 | } |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 266 | native int rsnAllocationGetType(int con, int id); |
| 267 | synchronized int nAllocationGetType(int id) { |
| 268 | return rsnAllocationGetType(mContext, id); |
| 269 | } |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 270 | |
| Jason Sams | 5edc608 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 271 | native void rsnAllocationResize1D(int con, int id, int dimX); |
| 272 | synchronized void nAllocationResize1D(int id, int dimX) { |
| 273 | rsnAllocationResize1D(mContext, id, dimX); |
| 274 | } |
| 275 | native void rsnAllocationResize2D(int con, int id, int dimX, int dimY); |
| 276 | synchronized void nAllocationResize2D(int id, int dimX, int dimY) { |
| 277 | rsnAllocationResize2D(mContext, id, dimX, dimY); |
| 278 | } |
| 279 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 280 | native int rsnFileA3DCreateFromAssetStream(int con, int assetStream); |
| 281 | synchronized int nFileA3DCreateFromAssetStream(int assetStream) { |
| 282 | return rsnFileA3DCreateFromAssetStream(mContext, assetStream); |
| 283 | } |
| 284 | native int rsnFileA3DGetNumIndexEntries(int con, int fileA3D); |
| 285 | synchronized int nFileA3DGetNumIndexEntries(int fileA3D) { |
| 286 | return rsnFileA3DGetNumIndexEntries(mContext, fileA3D); |
| 287 | } |
| 288 | native void rsnFileA3DGetIndexEntries(int con, int fileA3D, int numEntries, int[] IDs, String[] names); |
| 289 | synchronized void nFileA3DGetIndexEntries(int fileA3D, int numEntries, int[] IDs, String[] names) { |
| 290 | rsnFileA3DGetIndexEntries(mContext, fileA3D, numEntries, IDs, names); |
| 291 | } |
| 292 | native int rsnFileA3DGetEntryByIndex(int con, int fileA3D, int index); |
| 293 | synchronized int nFileA3DGetEntryByIndex(int fileA3D, int index) { |
| 294 | return rsnFileA3DGetEntryByIndex(mContext, fileA3D, index); |
| 295 | } |
| Jason Sams | bd1c3ad | 2009-08-03 16:03:08 -0700 | [diff] [blame] | 296 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 297 | native int rsnFontCreateFromFile(int con, String fileName, int size, int dpi); |
| 298 | synchronized int nFontCreateFromFile(String fileName, int size, int dpi) { |
| 299 | return rsnFontCreateFromFile(mContext, fileName, size, dpi); |
| 300 | } |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 301 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 302 | native void rsnAdapter1DBindAllocation(int con, int ad, int alloc); |
| 303 | synchronized void nAdapter1DBindAllocation(int ad, int alloc) { |
| 304 | rsnAdapter1DBindAllocation(mContext, ad, alloc); |
| 305 | } |
| 306 | native void rsnAdapter1DSetConstraint(int con, int ad, int dim, int value); |
| 307 | synchronized void nAdapter1DSetConstraint(int ad, int dim, int value) { |
| 308 | rsnAdapter1DSetConstraint(mContext, ad, dim, value); |
| 309 | } |
| 310 | native void rsnAdapter1DData(int con, int ad, int[] d); |
| 311 | synchronized void nAdapter1DData(int ad, int[] d) { |
| 312 | rsnAdapter1DData(mContext, ad, d); |
| 313 | } |
| 314 | native void rsnAdapter1DData(int con, int ad, float[] d); |
| 315 | synchronized void nAdapter1DData(int ad, float[] d) { |
| 316 | rsnAdapter1DData(mContext, ad, d); |
| 317 | } |
| 318 | native void rsnAdapter1DSubData(int con, int ad, int off, int count, int[] d); |
| 319 | synchronized void nAdapter1DSubData(int ad, int off, int count, int[] d) { |
| 320 | rsnAdapter1DSubData(mContext, ad, off, count, d); |
| 321 | } |
| 322 | native void rsnAdapter1DSubData(int con, int ad, int off, int count, float[] d); |
| 323 | synchronized void nAdapter1DSubData(int ad, int off, int count, float[] d) { |
| 324 | rsnAdapter1DSubData(mContext, ad, off, count, d); |
| 325 | } |
| 326 | native int rsnAdapter1DCreate(int con); |
| 327 | synchronized int nAdapter1DCreate() { |
| 328 | return rsnAdapter1DCreate(mContext); |
| 329 | } |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 330 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 331 | native void rsnAdapter2DBindAllocation(int con, int ad, int alloc); |
| 332 | synchronized void nAdapter2DBindAllocation(int ad, int alloc) { |
| 333 | rsnAdapter2DBindAllocation(mContext, ad, alloc); |
| 334 | } |
| 335 | native void rsnAdapter2DSetConstraint(int con, int ad, int dim, int value); |
| 336 | synchronized void nAdapter2DSetConstraint(int ad, int dim, int value) { |
| 337 | rsnAdapter2DSetConstraint(mContext, ad, dim, value); |
| 338 | } |
| 339 | native void rsnAdapter2DData(int con, int ad, int[] d); |
| 340 | synchronized void nAdapter2DData(int ad, int[] d) { |
| 341 | rsnAdapter2DData(mContext, ad, d); |
| 342 | } |
| 343 | native void rsnAdapter2DData(int con, int ad, float[] d); |
| 344 | synchronized void nAdapter2DData(int ad, float[] d) { |
| 345 | rsnAdapter2DData(mContext, ad, d); |
| 346 | } |
| 347 | native void rsnAdapter2DSubData(int con, int ad, int xoff, int yoff, int w, int h, int[] d); |
| 348 | synchronized void nAdapter2DSubData(int ad, int xoff, int yoff, int w, int h, int[] d) { |
| 349 | rsnAdapter2DSubData(mContext, ad, xoff, yoff, w, h, d); |
| 350 | } |
| 351 | native void rsnAdapter2DSubData(int con, int ad, int xoff, int yoff, int w, int h, float[] d); |
| 352 | synchronized void nAdapter2DSubData(int ad, int xoff, int yoff, int w, int h, float[] d) { |
| 353 | rsnAdapter2DSubData(mContext, ad, xoff, yoff, w, h, d); |
| 354 | } |
| 355 | native int rsnAdapter2DCreate(int con); |
| 356 | synchronized int nAdapter2DCreate() { |
| 357 | return rsnAdapter2DCreate(mContext); |
| 358 | } |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 359 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 360 | native void rsnScriptBindAllocation(int con, int script, int alloc, int slot); |
| 361 | synchronized void nScriptBindAllocation(int script, int alloc, int slot) { |
| 362 | rsnScriptBindAllocation(mContext, script, alloc, slot); |
| 363 | } |
| 364 | native void rsnScriptSetTimeZone(int con, int script, byte[] timeZone); |
| 365 | synchronized void nScriptSetTimeZone(int script, byte[] timeZone) { |
| 366 | rsnScriptSetTimeZone(mContext, script, timeZone); |
| 367 | } |
| 368 | native void rsnScriptInvoke(int con, int id, int slot); |
| 369 | synchronized void nScriptInvoke(int id, int slot) { |
| 370 | rsnScriptInvoke(mContext, id, slot); |
| 371 | } |
| 372 | native void rsnScriptInvokeV(int con, int id, int slot, byte[] params); |
| 373 | synchronized void nScriptInvokeV(int id, int slot, byte[] params) { |
| 374 | rsnScriptInvokeV(mContext, id, slot, params); |
| 375 | } |
| 376 | native void rsnScriptSetVarI(int con, int id, int slot, int val); |
| 377 | synchronized void nScriptSetVarI(int id, int slot, int val) { |
| 378 | rsnScriptSetVarI(mContext, id, slot, val); |
| 379 | } |
| Stephen Hines | 031ec58c | 2010-10-11 10:54:21 -0700 | [diff] [blame] | 380 | native void rsnScriptSetVarJ(int con, int id, int slot, long val); |
| 381 | synchronized void nScriptSetVarJ(int id, int slot, long val) { |
| 382 | rsnScriptSetVarJ(mContext, id, slot, val); |
| 383 | } |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 384 | native void rsnScriptSetVarF(int con, int id, int slot, float val); |
| 385 | synchronized void nScriptSetVarF(int id, int slot, float val) { |
| 386 | rsnScriptSetVarF(mContext, id, slot, val); |
| 387 | } |
| Stephen Hines | ca54ec3 | 2010-09-20 17:20:30 -0700 | [diff] [blame] | 388 | native void rsnScriptSetVarD(int con, int id, int slot, double val); |
| 389 | synchronized void nScriptSetVarD(int id, int slot, double val) { |
| 390 | rsnScriptSetVarD(mContext, id, slot, val); |
| 391 | } |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 392 | native void rsnScriptSetVarV(int con, int id, int slot, byte[] val); |
| 393 | synchronized void nScriptSetVarV(int id, int slot, byte[] val) { |
| 394 | rsnScriptSetVarV(mContext, id, slot, val); |
| 395 | } |
| Jason Sams | 6f4cf0b | 2010-11-16 17:37:02 -0800 | [diff] [blame] | 396 | native void rsnScriptSetVarObj(int con, int id, int slot, int val); |
| 397 | synchronized void nScriptSetVarObj(int id, int slot, int val) { |
| 398 | rsnScriptSetVarObj(mContext, id, slot, val); |
| 399 | } |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 400 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 401 | native void rsnScriptCBegin(int con); |
| 402 | synchronized void nScriptCBegin() { |
| 403 | rsnScriptCBegin(mContext); |
| 404 | } |
| 405 | native void rsnScriptCSetScript(int con, byte[] script, int offset, int length); |
| 406 | synchronized void nScriptCSetScript(byte[] script, int offset, int length) { |
| 407 | rsnScriptCSetScript(mContext, script, offset, length); |
| 408 | } |
| Shih-wei Liao | a914f34 | 2010-11-08 01:33:59 -0800 | [diff] [blame] | 409 | native int rsnScriptCCreate(int con, String val); |
| 410 | synchronized int nScriptCCreate(String val) { |
| 411 | return rsnScriptCCreate(mContext, val); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 412 | } |
| Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 413 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 414 | native void rsnSamplerBegin(int con); |
| 415 | synchronized void nSamplerBegin() { |
| 416 | rsnSamplerBegin(mContext); |
| 417 | } |
| 418 | native void rsnSamplerSet(int con, int param, int value); |
| 419 | synchronized void nSamplerSet(int param, int value) { |
| 420 | rsnSamplerSet(mContext, param, value); |
| 421 | } |
| Alex Sakhartchouk | f5b3510 | 2010-09-30 11:36:37 -0700 | [diff] [blame] | 422 | native void rsnSamplerSet2(int con, int param, float value); |
| 423 | synchronized void nSamplerSet2(int param, float value) { |
| 424 | rsnSamplerSet2(mContext, param, value); |
| 425 | } |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 426 | native int rsnSamplerCreate(int con); |
| 427 | synchronized int nSamplerCreate() { |
| 428 | return rsnSamplerCreate(mContext); |
| 429 | } |
| Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 430 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 431 | native void rsnProgramStoreBegin(int con, int in, int out); |
| 432 | synchronized void nProgramStoreBegin(int in, int out) { |
| 433 | rsnProgramStoreBegin(mContext, in, out); |
| 434 | } |
| 435 | native void rsnProgramStoreDepthFunc(int con, int func); |
| 436 | synchronized void nProgramStoreDepthFunc(int func) { |
| 437 | rsnProgramStoreDepthFunc(mContext, func); |
| 438 | } |
| 439 | native void rsnProgramStoreDepthMask(int con, boolean enable); |
| 440 | synchronized void nProgramStoreDepthMask(boolean enable) { |
| 441 | rsnProgramStoreDepthMask(mContext, enable); |
| 442 | } |
| 443 | native void rsnProgramStoreColorMask(int con, boolean r, boolean g, boolean b, boolean a); |
| 444 | synchronized void nProgramStoreColorMask(boolean r, boolean g, boolean b, boolean a) { |
| 445 | rsnProgramStoreColorMask(mContext, r, g, b, a); |
| 446 | } |
| 447 | native void rsnProgramStoreBlendFunc(int con, int src, int dst); |
| 448 | synchronized void nProgramStoreBlendFunc(int src, int dst) { |
| 449 | rsnProgramStoreBlendFunc(mContext, src, dst); |
| 450 | } |
| 451 | native void rsnProgramStoreDither(int con, boolean enable); |
| 452 | synchronized void nProgramStoreDither(boolean enable) { |
| 453 | rsnProgramStoreDither(mContext, enable); |
| 454 | } |
| 455 | native int rsnProgramStoreCreate(int con); |
| 456 | synchronized int nProgramStoreCreate() { |
| 457 | return rsnProgramStoreCreate(mContext); |
| 458 | } |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 459 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 460 | native int rsnProgramRasterCreate(int con, boolean pointSmooth, boolean lineSmooth, boolean pointSprite); |
| 461 | synchronized int nProgramRasterCreate(boolean pointSmooth, boolean lineSmooth, boolean pointSprite) { |
| 462 | return rsnProgramRasterCreate(mContext, pointSmooth, lineSmooth, pointSprite); |
| 463 | } |
| 464 | native void rsnProgramRasterSetLineWidth(int con, int pr, float v); |
| 465 | synchronized void nProgramRasterSetLineWidth(int pr, float v) { |
| 466 | rsnProgramRasterSetLineWidth(mContext, pr, v); |
| 467 | } |
| 468 | native void rsnProgramRasterSetCullMode(int con, int pr, int mode); |
| 469 | synchronized void nProgramRasterSetCullMode(int pr, int mode) { |
| 470 | rsnProgramRasterSetCullMode(mContext, pr, mode); |
| 471 | } |
| Jason Sams | 1fe9b8c | 2009-06-11 14:46:10 -0700 | [diff] [blame] | 472 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 473 | native void rsnProgramBindConstants(int con, int pv, int slot, int mID); |
| 474 | synchronized void nProgramBindConstants(int pv, int slot, int mID) { |
| 475 | rsnProgramBindConstants(mContext, pv, slot, mID); |
| 476 | } |
| 477 | native void rsnProgramBindTexture(int con, int vpf, int slot, int a); |
| 478 | synchronized void nProgramBindTexture(int vpf, int slot, int a) { |
| 479 | rsnProgramBindTexture(mContext, vpf, slot, a); |
| 480 | } |
| 481 | native void rsnProgramBindSampler(int con, int vpf, int slot, int s); |
| 482 | synchronized void nProgramBindSampler(int vpf, int slot, int s) { |
| 483 | rsnProgramBindSampler(mContext, vpf, slot, s); |
| 484 | } |
| Alex Sakhartchouk | b89aaac | 2010-09-23 16:16:33 -0700 | [diff] [blame] | 485 | native int rsnProgramFragmentCreate(int con, String shader, int[] params); |
| 486 | synchronized int nProgramFragmentCreate(String shader, int[] params) { |
| 487 | return rsnProgramFragmentCreate(mContext, shader, params); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 488 | } |
| Alex Sakhartchouk | b89aaac | 2010-09-23 16:16:33 -0700 | [diff] [blame] | 489 | native int rsnProgramVertexCreate(int con, String shader, int[] params); |
| 490 | synchronized int nProgramVertexCreate(String shader, int[] params) { |
| 491 | return rsnProgramVertexCreate(mContext, shader, params); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 492 | } |
| Alex Sakhartchouk | 164aaed | 2010-07-01 16:14:06 -0700 | [diff] [blame] | 493 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 494 | native int rsnMeshCreate(int con, int vtxCount, int indexCount); |
| 495 | synchronized int nMeshCreate(int vtxCount, int indexCount) { |
| 496 | return rsnMeshCreate(mContext, vtxCount, indexCount); |
| 497 | } |
| 498 | native void rsnMeshBindVertex(int con, int id, int alloc, int slot); |
| 499 | synchronized void nMeshBindVertex(int id, int alloc, int slot) { |
| 500 | rsnMeshBindVertex(mContext, id, alloc, slot); |
| 501 | } |
| 502 | native void rsnMeshBindIndex(int con, int id, int alloc, int prim, int slot); |
| 503 | synchronized void nMeshBindIndex(int id, int alloc, int prim, int slot) { |
| 504 | rsnMeshBindIndex(mContext, id, alloc, prim, slot); |
| 505 | } |
| Alex Sakhartchouk | 9d71e21 | 2010-11-08 15:10:52 -0800 | [diff] [blame] | 506 | native void rsnMeshInitVertexAttribs(int con, int id); |
| 507 | synchronized void nMeshInitVertexAttribs(int id) { |
| 508 | rsnMeshInitVertexAttribs(mContext, id); |
| 509 | } |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 510 | native int rsnMeshGetVertexBufferCount(int con, int id); |
| 511 | synchronized int nMeshGetVertexBufferCount(int id) { |
| 512 | return rsnMeshGetVertexBufferCount(mContext, id); |
| 513 | } |
| 514 | native int rsnMeshGetIndexCount(int con, int id); |
| 515 | synchronized int nMeshGetIndexCount(int id) { |
| 516 | return rsnMeshGetIndexCount(mContext, id); |
| 517 | } |
| 518 | native void rsnMeshGetVertices(int con, int id, int[] vtxIds, int vtxIdCount); |
| 519 | synchronized void nMeshGetVertices(int id, int[] vtxIds, int vtxIdCount) { |
| 520 | rsnMeshGetVertices(mContext, id, vtxIds, vtxIdCount); |
| 521 | } |
| 522 | native void rsnMeshGetIndices(int con, int id, int[] idxIds, int[] primitives, int vtxIdCount); |
| 523 | synchronized void nMeshGetIndices(int id, int[] idxIds, int[] primitives, int vtxIdCount) { |
| 524 | rsnMeshGetIndices(mContext, id, idxIds, primitives, vtxIdCount); |
| 525 | } |
| 526 | |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 527 | |
| Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 528 | protected int mDev; |
| 529 | protected int mContext; |
| Romain Guy | 650a3eb | 2009-08-31 14:06:43 -0700 | [diff] [blame] | 530 | @SuppressWarnings({"FieldCanBeLocal"}) |
| Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 531 | protected MessageThread mMessageThread; |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 532 | |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 533 | Element mElement_U8; |
| 534 | Element mElement_I8; |
| 535 | Element mElement_U16; |
| 536 | Element mElement_I16; |
| 537 | Element mElement_U32; |
| 538 | Element mElement_I32; |
| Stephen Hines | 52d8363 | 2010-10-11 16:10:42 -0700 | [diff] [blame] | 539 | Element mElement_U64; |
| Stephen Hines | ef1dac2 | 2010-10-01 15:39:33 -0700 | [diff] [blame] | 540 | Element mElement_I64; |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 541 | Element mElement_F32; |
| Stephen Hines | 02f41705 | 2010-09-30 15:19:22 -0700 | [diff] [blame] | 542 | Element mElement_F64; |
| Jason Sams | f110d4b | 2010-06-21 17:42:41 -0700 | [diff] [blame] | 543 | Element mElement_BOOLEAN; |
| Jason Sams | 3c0dfba | 2009-09-27 17:50:38 -0700 | [diff] [blame] | 544 | |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 545 | Element mElement_ELEMENT; |
| 546 | Element mElement_TYPE; |
| 547 | Element mElement_ALLOCATION; |
| 548 | Element mElement_SAMPLER; |
| 549 | Element mElement_SCRIPT; |
| 550 | Element mElement_MESH; |
| 551 | Element mElement_PROGRAM_FRAGMENT; |
| 552 | Element mElement_PROGRAM_VERTEX; |
| 553 | Element mElement_PROGRAM_RASTER; |
| 554 | Element mElement_PROGRAM_STORE; |
| Jason Sams | a70f416 | 2010-03-26 15:33:42 -0700 | [diff] [blame] | 555 | |
| Jason Sams | 3c0dfba | 2009-09-27 17:50:38 -0700 | [diff] [blame] | 556 | Element mElement_A_8; |
| 557 | Element mElement_RGB_565; |
| 558 | Element mElement_RGB_888; |
| 559 | Element mElement_RGBA_5551; |
| 560 | Element mElement_RGBA_4444; |
| 561 | Element mElement_RGBA_8888; |
| 562 | |
| Jason Sams | 8cb39de | 2010-06-01 15:47:01 -0700 | [diff] [blame] | 563 | Element mElement_FLOAT_2; |
| 564 | Element mElement_FLOAT_3; |
| 565 | Element mElement_FLOAT_4; |
| 566 | Element mElement_UCHAR_4; |
| Jason Sams | 7d787b4 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 567 | |
| Jason Sams | 1d45c47 | 2010-08-25 14:31:48 -0700 | [diff] [blame] | 568 | Element mElement_MATRIX_4X4; |
| 569 | Element mElement_MATRIX_3X3; |
| 570 | Element mElement_MATRIX_2X2; |
| 571 | |
| Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 572 | Sampler mSampler_CLAMP_NEAREST; |
| 573 | Sampler mSampler_CLAMP_LINEAR; |
| 574 | Sampler mSampler_CLAMP_LINEAR_MIP_LINEAR; |
| 575 | Sampler mSampler_WRAP_NEAREST; |
| 576 | Sampler mSampler_WRAP_LINEAR; |
| 577 | Sampler mSampler_WRAP_LINEAR_MIP_LINEAR; |
| 578 | |
| Alex Sakhartchouk | d36f248 | 2010-08-24 11:37:33 -0700 | [diff] [blame] | 579 | ProgramStore mProgramStore_BLEND_NONE_DEPTH_TEST; |
| 580 | ProgramStore mProgramStore_BLEND_NONE_DEPTH_NO_DEPTH; |
| 581 | ProgramStore mProgramStore_BLEND_NONE_DEPTH_NO_TEST; |
| 582 | ProgramStore mProgramStore_BLEND_NONE_DEPTH_NO_WRITE; |
| 583 | ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_TEST; |
| 584 | ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_NO_DEPTH; |
| 585 | ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_NO_TEST; |
| 586 | ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_NO_WRITE; |
| 587 | ProgramStore mProgramStore_BLEND_ADD_DEPTH_TEST; |
| 588 | ProgramStore mProgramStore_BLEND_ADD_DEPTH_NO_DEPTH; |
| 589 | ProgramStore mProgramStore_BLEND_ADD_DEPTH_NO_TEST; |
| 590 | ProgramStore mProgramStore_BLEND_ADD_DEPTH_NO_WRITE; |
| Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame] | 591 | |
| Alex Sakhartchouk | d36f248 | 2010-08-24 11:37:33 -0700 | [diff] [blame] | 592 | ProgramRaster mProgramRaster_CULL_BACK; |
| 593 | ProgramRaster mProgramRaster_CULL_FRONT; |
| 594 | ProgramRaster mProgramRaster_CULL_NONE; |
| Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame] | 595 | |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 596 | /////////////////////////////////////////////////////////////////////////////////// |
| Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 597 | // |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 598 | |
| Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 599 | /** |
| 600 | * Base class application should derive from for handling RS messages |
| 601 | * comming from their scripts. When a script calls sendToClient the data |
| 602 | * fields will be filled in and then the run method called by a message |
| 603 | * handling thread. This will occur some time after sendToClient completes |
| 604 | * in the script. |
| 605 | * |
| 606 | */ |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 607 | public static class RSMessage implements Runnable { |
| 608 | protected int[] mData; |
| 609 | protected int mID; |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 610 | protected int mLength; |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 611 | public void run() { |
| 612 | } |
| 613 | } |
| Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 614 | /** |
| 615 | * If an application is expecting messages it should set this field to an |
| 616 | * instance of RSMessage. This instance will receive all the user messages |
| 617 | * sent from sendToClient by scripts from this context. |
| 618 | * |
| 619 | */ |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 620 | public RSMessage mMessageCallback = null; |
| 621 | |
| Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 622 | /** |
| 623 | * Runtime error base class. An application should derive from this class |
| 624 | * if it wishes to install an error handler. When errors occur at runtime |
| 625 | * the fields in this class will be filled and the run method called. |
| 626 | * |
| 627 | */ |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 628 | public static class RSAsyncError implements Runnable { |
| 629 | protected String mErrorMessage; |
| 630 | protected int mErrorNum; |
| 631 | public void run() { |
| 632 | } |
| 633 | } |
| Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 634 | |
| 635 | /** |
| 636 | * Application Error handler. All runtime errors will be dispatched to the |
| 637 | * instance of RSAsyncError set here. If this field is null a |
| 638 | * RSRuntimeException will instead be thrown with details about the error. |
| 639 | * This will cause program termaination. |
| 640 | * |
| 641 | */ |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 642 | public RSAsyncError mErrorCallback = null; |
| 643 | |
| Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 644 | /** |
| 645 | * RenderScript worker threads priority enumeration. The default value is |
| 646 | * NORMAL. Applications wishing to do background processing such as |
| 647 | * wallpapers should set their priority to LOW to avoid starving forground |
| 648 | * processes. |
| 649 | */ |
| Jason Sams | 7d787b4 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 650 | public enum Priority { |
| 651 | LOW (5), //ANDROID_PRIORITY_BACKGROUND + 5 |
| 652 | NORMAL (-4); //ANDROID_PRIORITY_DISPLAY |
| 653 | |
| 654 | int mID; |
| 655 | Priority(int id) { |
| 656 | mID = id; |
| 657 | } |
| 658 | } |
| 659 | |
| Jason Sams | 771bebb | 2009-12-07 12:40:12 -0800 | [diff] [blame] | 660 | void validate() { |
| 661 | if (mContext == 0) { |
| Jason Sams | c1d6210 | 2010-11-04 14:32:19 -0700 | [diff] [blame] | 662 | throw new RSInvalidStateException("Calling RS with no Context active."); |
| Jason Sams | 771bebb | 2009-12-07 12:40:12 -0800 | [diff] [blame] | 663 | } |
| 664 | } |
| 665 | |
| Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 666 | |
| 667 | /** |
| 668 | * Change the priority of the worker threads for this context. |
| 669 | * |
| 670 | * @param p New priority to be set. |
| 671 | */ |
| Jason Sams | 7d787b4 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 672 | public void contextSetPriority(Priority p) { |
| Jason Sams | 5dbfe93 | 2010-01-27 14:41:43 -0800 | [diff] [blame] | 673 | validate(); |
| Jason Sams | 7d787b4 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 674 | nContextSetPriority(p.mID); |
| 675 | } |
| 676 | |
| Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 677 | protected static class MessageThread extends Thread { |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 678 | RenderScript mRS; |
| 679 | boolean mRun = true; |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 680 | int[] auxData = new int[2]; |
| 681 | |
| 682 | public static final int RS_MESSAGE_TO_CLIENT_NONE = 0; |
| 683 | public static final int RS_MESSAGE_TO_CLIENT_EXCEPTION = 1; |
| 684 | public static final int RS_MESSAGE_TO_CLIENT_RESIZE = 2; |
| 685 | public static final int RS_MESSAGE_TO_CLIENT_ERROR = 3; |
| 686 | public static final int RS_MESSAGE_TO_CLIENT_USER = 4; |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 687 | |
| 688 | MessageThread(RenderScript rs) { |
| 689 | super("RSMessageThread"); |
| 690 | mRS = rs; |
| 691 | |
| 692 | } |
| 693 | |
| 694 | public void run() { |
| 695 | // This function is a temporary solution. The final solution will |
| 696 | // used typed allocations where the message id is the type indicator. |
| 697 | int[] rbuf = new int[16]; |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 698 | mRS.nContextInitToClient(mRS.mContext); |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 699 | while(mRun) { |
| Jason Sams | 1d45c47 | 2010-08-25 14:31:48 -0700 | [diff] [blame] | 700 | rbuf[0] = 0; |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 701 | int msg = mRS.nContextPeekMessage(mRS.mContext, auxData, true); |
| 702 | int size = auxData[1]; |
| 703 | int subID = auxData[0]; |
| 704 | |
| 705 | if (msg == RS_MESSAGE_TO_CLIENT_USER) { |
| 706 | if ((size>>2) >= rbuf.length) { |
| 707 | rbuf = new int[(size + 3) >> 2]; |
| 708 | } |
| 709 | mRS.nContextGetUserMessage(mRS.mContext, rbuf); |
| 710 | |
| 711 | if(mRS.mMessageCallback != null) { |
| 712 | mRS.mMessageCallback.mData = rbuf; |
| 713 | mRS.mMessageCallback.mID = subID; |
| 714 | mRS.mMessageCallback.mLength = size; |
| 715 | mRS.mMessageCallback.run(); |
| Jason Sams | 1d45c47 | 2010-08-25 14:31:48 -0700 | [diff] [blame] | 716 | } else { |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 717 | 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] | 718 | } |
| Stephen Hines | ab98bb6 | 2010-09-24 14:38:30 -0700 | [diff] [blame] | 719 | continue; |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 720 | } |
| Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 721 | |
| 722 | if (msg == RS_MESSAGE_TO_CLIENT_ERROR) { |
| 723 | String e = mRS.nContextGetErrorMessage(mRS.mContext); |
| 724 | |
| 725 | if(mRS.mErrorCallback != null) { |
| 726 | mRS.mErrorCallback.mErrorMessage = e; |
| 727 | mRS.mErrorCallback.mErrorNum = subID; |
| 728 | mRS.mErrorCallback.run(); |
| 729 | } else { |
| 730 | //throw new RSRuntimeException("Received error num " + subID + ", details: " + e); |
| 731 | } |
| 732 | continue; |
| 733 | } |
| 734 | |
| 735 | // 2: teardown. |
| 736 | // But we want to avoid starving other threads during |
| 737 | // teardown by yielding until the next line in the destructor |
| 738 | // can execute to set mRun = false |
| 739 | try { |
| 740 | sleep(1, 0); |
| 741 | } catch(InterruptedException e) { |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 742 | } |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 743 | } |
| Jason Sams | 3bc47d4 | 2009-11-12 15:10:25 -0800 | [diff] [blame] | 744 | Log.d(LOG_TAG, "MessageThread exiting."); |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 745 | } |
| 746 | } |
| 747 | |
| Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 748 | RenderScript() { |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 749 | } |
| 750 | |
| Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 751 | /** |
| 752 | * Create a basic RenderScript context. |
| 753 | * |
| 754 | * |
| 755 | * @return RenderScript |
| 756 | */ |
| Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 757 | public static RenderScript create() { |
| 758 | RenderScript rs = new RenderScript(); |
| 759 | |
| 760 | rs.mDev = rs.nDeviceCreate(); |
| 761 | rs.mContext = rs.nContextCreate(rs.mDev, 0); |
| 762 | rs.mMessageThread = new MessageThread(rs); |
| 763 | rs.mMessageThread.start(); |
| 764 | Element.initPredefined(rs); |
| 765 | return rs; |
| Jason Sams | efd9b6fb | 2009-11-03 13:58:36 -0800 | [diff] [blame] | 766 | } |
| 767 | |
| Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 768 | /** |
| 769 | * Print the currently available debugging information about the state of |
| 770 | * the RS context to the log. |
| 771 | * |
| 772 | * |
| 773 | * @param bits Currently ignored. |
| 774 | */ |
| Jason Sams | 715333b | 2009-11-17 17:26:46 -0800 | [diff] [blame] | 775 | public void contextDump(int bits) { |
| Jason Sams | 5dbfe93 | 2010-01-27 14:41:43 -0800 | [diff] [blame] | 776 | validate(); |
| Jason Sams | 715333b | 2009-11-17 17:26:46 -0800 | [diff] [blame] | 777 | nContextDump(bits); |
| 778 | } |
| 779 | |
| Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 780 | /** |
| 781 | * Wait for any commands in the fifo between the java bindings and native to |
| 782 | * be processed. |
| 783 | * |
| 784 | */ |
| Jason Sams | 96ed4cf | 2010-06-15 12:15:57 -0700 | [diff] [blame] | 785 | public void finish() { |
| 786 | nContextFinish(); |
| 787 | } |
| 788 | |
| Jason Sams | 27676fe | 2010-11-10 17:00:59 -0800 | [diff] [blame] | 789 | /** |
| 790 | * Destroy this renderscript context. Once this function is called its no |
| 791 | * longer legal to use this or any objects created by this context. |
| 792 | * |
| 793 | */ |
| Jason Sams | f5b4596 | 2009-08-25 14:49:07 -0700 | [diff] [blame] | 794 | public void destroy() { |
| Jason Sams | 5dbfe93 | 2010-01-27 14:41:43 -0800 | [diff] [blame] | 795 | validate(); |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 796 | nContextDeinitToClient(mContext); |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 797 | mMessageThread.mRun = false; |
| Jason Sams | a8bf942 | 2010-09-16 13:43:19 -0700 | [diff] [blame] | 798 | try { |
| 799 | mMessageThread.join(); |
| 800 | } catch(InterruptedException e) { |
| 801 | } |
| Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 802 | |
| Jason Sams | 2e1872f | 2010-08-17 16:25:41 -0700 | [diff] [blame] | 803 | nContextDestroy(); |
| Jason Sams | f5b4596 | 2009-08-25 14:49:07 -0700 | [diff] [blame] | 804 | mContext = 0; |
| 805 | |
| 806 | nDeviceDestroy(mDev); |
| 807 | mDev = 0; |
| 808 | } |
| Jason Sams | 02fb2cb | 2009-05-28 15:37:57 -0700 | [diff] [blame] | 809 | |
| Jason Sams | a9e7a05 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 810 | boolean isAlive() { |
| 811 | return mContext != 0; |
| 812 | } |
| 813 | |
| Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 814 | protected int safeID(BaseObj o) { |
| Jason Sams | 6b9dec0 | 2009-09-23 16:38:37 -0700 | [diff] [blame] | 815 | if(o != null) { |
| Jason Sams | 06d69de | 2010-11-09 17:11:40 -0800 | [diff] [blame] | 816 | return o.getID(); |
| Jason Sams | d8e4161 | 2009-08-20 17:22:40 -0700 | [diff] [blame] | 817 | } |
| Jason Sams | 6b9dec0 | 2009-09-23 16:38:37 -0700 | [diff] [blame] | 818 | return 0; |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 819 | } |
| Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 820 | } |