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