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