blob: 822ac6fedaccd3a6d7d1f21a631a4adf013230fc [file] [log] [blame]
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001/*
Stephen Hinesbe74bdd2012-02-03 15:29:36 -08002 * Copyright (C) 2008-2012 The Android Open Source Project
Jack Palevich60aa3ea2009-05-26 13:45:08 -07003 *
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 Sams94d8e90a2009-06-10 16:09:05 -070017package android.renderscript;
Jack Palevich60aa3ea2009-05-26 13:45:08 -070018
Jason Samsa6f338c2012-02-24 16:22:16 -080019import java.io.File;
Jason Samsfe1d5ff2012-03-23 11:47:26 -070020import java.lang.reflect.Field;
Jason Sams36e612a2009-07-31 16:26:13 -070021
Shih-wei Liao6b32fab2010-12-10 01:03:59 -080022import android.content.Context;
Stephen Hines4382467a2011-08-01 15:02:34 -070023import android.content.pm.ApplicationInfo;
24import android.content.pm.PackageManager;
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080025import android.content.res.AssetManager;
Jason Samsb8c5a842009-07-31 20:40:47 -070026import android.graphics.Bitmap;
Romain Guy650a3eb2009-08-31 14:06:43 -070027import android.graphics.BitmapFactory;
Jason Samsfaa32b32011-06-20 16:58:04 -070028import android.graphics.SurfaceTexture;
Glenn Kasten260c77a2011-06-01 17:25:54 -070029import android.os.Process;
Jason Sams36e612a2009-07-31 16:26:13 -070030import android.util.Log;
31import android.view.Surface;
Dan Morrille4d9a012013-03-28 18:10:43 -070032import android.os.SystemProperties;
Jack Palevich43702d82009-05-28 13:38:16 -070033
Jack Palevich60aa3ea2009-05-26 13:45:08 -070034
Stephen Hines4382467a2011-08-01 15:02:34 -070035
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070036/**
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080037 * Renderscript base master class. An instance of this class creates native
Jason Sams27676fe2010-11-10 17:00:59 -080038 * worker threads for processing commands from this object. This base class
39 * does not provide any extended capabilities beyond simple data processing.
40 * For extended capabilities use derived classes such as RenderScriptGL.
41 *
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080042 * <div class="special reference">
43 * <h3>Developer Guides</h3>
44 * <p>For more information about creating an application that uses Renderscript, read the
Scott Mainb47fa162013-02-05 14:23:13 -080045 * <a href="{@docRoot}guide/topics/renderscript/index.html">Renderscript</a> developer guide.</p>
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080046 * </div>
Jason Samse29d4712009-07-23 15:19:03 -070047 **/
Jack Palevich60aa3ea2009-05-26 13:45:08 -070048public class RenderScript {
Jason Sams3bc47d42009-11-12 15:10:25 -080049 static final String LOG_TAG = "RenderScript_jni";
Jason Samsbf6ef8d2010-12-06 15:59:59 -080050 static final boolean DEBUG = false;
Romain Guy650a3eb2009-08-31 14:06:43 -070051 @SuppressWarnings({"UnusedDeclaration", "deprecation"})
Joe Onorato43a17652011-04-06 19:22:23 -070052 static final boolean LOG_ENABLED = false;
Jack Palevich60aa3ea2009-05-26 13:45:08 -070053
Shih-wei Liao6b32fab2010-12-10 01:03:59 -080054 private Context mApplicationContext;
Jack Palevich60aa3ea2009-05-26 13:45:08 -070055
Shih-wei Liao6b32fab2010-12-10 01:03:59 -080056 /*
Jack Palevich60aa3ea2009-05-26 13:45:08 -070057 * We use a class initializer to allow the native code to cache some
58 * field offsets.
59 */
Dan Morrille4d9a012013-03-28 18:10:43 -070060 @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"}) // TODO: now used locally; remove?
Jason Samsbf6ef8d2010-12-06 15:59:59 -080061 static boolean sInitialized;
62 native static void _nInit();
Jack Palevich60aa3ea2009-05-26 13:45:08 -070063
Jason Samsdba3ba52009-07-30 14:56:12 -070064
Jack Palevich60aa3ea2009-05-26 13:45:08 -070065 static {
66 sInitialized = false;
Dan Morrille4d9a012013-03-28 18:10:43 -070067 if (!SystemProperties.getBoolean("config.disable_renderscript", false)) {
68 try {
69 System.loadLibrary("rs_jni");
70 _nInit();
71 sInitialized = true;
72 } catch (UnsatisfiedLinkError e) {
73 Log.e(LOG_TAG, "Error loading RS jni library: " + e);
74 throw new RSRuntimeException("Error loading RS jni library: " + e);
75 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -070076 }
77 }
78
Jason Sams2e1872f2010-08-17 16:25:41 -070079 // Non-threadsafe functions.
Jason Sams36e612a2009-07-31 16:26:13 -070080 native int nDeviceCreate();
81 native void nDeviceDestroy(int dev);
Jason Samsebfb4362009-09-23 13:57:02 -070082 native void nDeviceSetConfig(int dev, int param, int value);
Jason Samsedbfabd2011-05-17 15:01:29 -070083 native int nContextGetUserMessage(int con, int[] data);
Jason Sams1c415172010-11-08 17:06:46 -080084 native String nContextGetErrorMessage(int con);
Jason Samsedbfabd2011-05-17 15:01:29 -070085 native int nContextPeekMessage(int con, int[] subID);
Jason Sams2e1872f2010-08-17 16:25:41 -070086 native void nContextInitToClient(int con);
87 native void nContextDeinitToClient(int con);
Jason Sams3eaa3382009-06-10 15:04:38 -070088
Jason Samsa6f338c2012-02-24 16:22:16 -080089 /**
90 * Name of the file that holds the object cache.
91 */
92 private static final String CACHE_PATH = "com.android.renderscript.cache";
Jason Sams1a4e1f32012-02-24 17:51:24 -080093 static String mCachePath;
Jason Samsa6f338c2012-02-24 16:22:16 -080094
95 /**
96 * Sets the directory to use as a persistent storage for the
97 * renderscript object file cache.
98 *
99 * @hide
100 * @param cacheDir A directory the current process can write to
101 */
Jason Samsa6f338c2012-02-24 16:22:16 -0800102 public static void setupDiskCache(File cacheDir) {
Dan Morrille4d9a012013-03-28 18:10:43 -0700103 if (!sInitialized) {
104 Log.e(LOG_TAG, "RenderScript.setupDiskCache() called when disabled");
105 return;
106 }
107
Jason Samsa6f338c2012-02-24 16:22:16 -0800108 File f = new File(cacheDir, CACHE_PATH);
109 mCachePath = f.getAbsolutePath();
110 f.mkdirs();
111 }
112
Jason Samsadd26dc2013-02-22 18:43:45 -0800113 public enum ContextType {
114 NORMAL (0),
115 DEBUG (1),
116 PROFILE (2);
117
118 int mID;
119 ContextType(int id) {
120 mID = id;
121 }
122 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800123
Jason Sams2e1872f2010-08-17 16:25:41 -0700124 // Methods below are wrapped to protect the non-threadsafe
125 // lockless fifo.
Stephen Hines4382467a2011-08-01 15:02:34 -0700126 native int rsnContextCreateGL(int dev, int ver, int sdkVer,
Jason Sams11c8af92010-10-13 15:31:10 -0700127 int colorMin, int colorPref,
128 int alphaMin, int alphaPref,
129 int depthMin, int depthPref,
130 int stencilMin, int stencilPref,
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700131 int samplesMin, int samplesPref, float samplesQ, int dpi);
Stephen Hines4382467a2011-08-01 15:02:34 -0700132 synchronized int nContextCreateGL(int dev, int ver, int sdkVer,
Jason Sams11c8af92010-10-13 15:31:10 -0700133 int colorMin, int colorPref,
134 int alphaMin, int alphaPref,
135 int depthMin, int depthPref,
136 int stencilMin, int stencilPref,
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700137 int samplesMin, int samplesPref, float samplesQ, int dpi) {
Stephen Hines4382467a2011-08-01 15:02:34 -0700138 return rsnContextCreateGL(dev, ver, sdkVer, colorMin, colorPref,
Jason Sams11c8af92010-10-13 15:31:10 -0700139 alphaMin, alphaPref, depthMin, depthPref,
140 stencilMin, stencilPref,
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700141 samplesMin, samplesPref, samplesQ, dpi);
Jason Sams2e1872f2010-08-17 16:25:41 -0700142 }
Jason Samsadd26dc2013-02-22 18:43:45 -0800143 native int rsnContextCreate(int dev, int ver, int sdkVer, int contextType);
144 synchronized int nContextCreate(int dev, int ver, int sdkVer, int contextType) {
145 return rsnContextCreate(dev, ver, sdkVer, contextType);
Jason Sams2e1872f2010-08-17 16:25:41 -0700146 }
147 native void rsnContextDestroy(int con);
148 synchronized void nContextDestroy() {
Jason Samsd1ac9812011-01-18 18:12:26 -0800149 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700150 rsnContextDestroy(mContext);
151 }
152 native void rsnContextSetSurface(int con, int w, int h, Surface sur);
153 synchronized void nContextSetSurface(int w, int h, Surface sur) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800154 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700155 rsnContextSetSurface(mContext, w, h, sur);
156 }
Jason Samsfaa32b32011-06-20 16:58:04 -0700157 native void rsnContextSetSurfaceTexture(int con, int w, int h, SurfaceTexture sur);
158 synchronized void nContextSetSurfaceTexture(int w, int h, SurfaceTexture sur) {
159 validate();
160 rsnContextSetSurfaceTexture(mContext, w, h, sur);
161 }
Jason Sams2e1872f2010-08-17 16:25:41 -0700162 native void rsnContextSetPriority(int con, int p);
163 synchronized void nContextSetPriority(int p) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800164 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700165 rsnContextSetPriority(mContext, p);
166 }
167 native void rsnContextDump(int con, int bits);
168 synchronized void nContextDump(int bits) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800169 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700170 rsnContextDump(mContext, bits);
171 }
172 native void rsnContextFinish(int con);
173 synchronized void nContextFinish() {
Jason Samsd1ac9812011-01-18 18:12:26 -0800174 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700175 rsnContextFinish(mContext);
176 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700177
Jason Sams455d6442013-02-05 19:20:18 -0800178 native void rsnContextSendMessage(int con, int id, int[] data);
179 synchronized void nContextSendMessage(int id, int[] data) {
180 validate();
181 rsnContextSendMessage(mContext, id, data);
182 }
183
Jason Sams2e1872f2010-08-17 16:25:41 -0700184 native void rsnContextBindRootScript(int con, int script);
185 synchronized void nContextBindRootScript(int script) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800186 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700187 rsnContextBindRootScript(mContext, script);
188 }
189 native void rsnContextBindSampler(int con, int sampler, int slot);
190 synchronized void nContextBindSampler(int sampler, int slot) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800191 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700192 rsnContextBindSampler(mContext, sampler, slot);
193 }
194 native void rsnContextBindProgramStore(int con, int pfs);
195 synchronized void nContextBindProgramStore(int pfs) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800196 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700197 rsnContextBindProgramStore(mContext, pfs);
198 }
199 native void rsnContextBindProgramFragment(int con, int pf);
200 synchronized void nContextBindProgramFragment(int pf) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800201 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700202 rsnContextBindProgramFragment(mContext, pf);
203 }
204 native void rsnContextBindProgramVertex(int con, int pv);
205 synchronized void nContextBindProgramVertex(int pv) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800206 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700207 rsnContextBindProgramVertex(mContext, pv);
208 }
209 native void rsnContextBindProgramRaster(int con, int pr);
210 synchronized void nContextBindProgramRaster(int pr) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800211 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700212 rsnContextBindProgramRaster(mContext, pr);
213 }
214 native void rsnContextPause(int con);
215 synchronized void nContextPause() {
Jason Samsd1ac9812011-01-18 18:12:26 -0800216 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700217 rsnContextPause(mContext);
218 }
219 native void rsnContextResume(int con);
220 synchronized void nContextResume() {
Jason Samsd1ac9812011-01-18 18:12:26 -0800221 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700222 rsnContextResume(mContext);
223 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700224
Jason Sams2e1872f2010-08-17 16:25:41 -0700225 native void rsnAssignName(int con, int obj, byte[] name);
226 synchronized void nAssignName(int obj, byte[] name) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800227 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700228 rsnAssignName(mContext, obj, name);
229 }
230 native String rsnGetName(int con, int obj);
231 synchronized String nGetName(int obj) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800232 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700233 return rsnGetName(mContext, obj);
234 }
235 native void rsnObjDestroy(int con, int id);
236 synchronized void nObjDestroy(int id) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800237 // There is a race condition here. The calling code may be run
238 // by the gc while teardown is occuring. This protects againts
239 // deleting dead objects.
240 if (mContext != 0) {
241 rsnObjDestroy(mContext, id);
242 }
Jason Sams2e1872f2010-08-17 16:25:41 -0700243 }
Jason Samsfe08d992009-05-27 14:45:32 -0700244
Jason Sams2e1872f2010-08-17 16:25:41 -0700245 native int rsnElementCreate(int con, int type, int kind, boolean norm, int vecSize);
246 synchronized int nElementCreate(int type, int kind, boolean norm, int vecSize) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800247 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700248 return rsnElementCreate(mContext, type, kind, norm, vecSize);
249 }
Jason Sams70d4e502010-09-02 17:35:23 -0700250 native int rsnElementCreate2(int con, int[] elements, String[] names, int[] arraySizes);
251 synchronized int nElementCreate2(int[] elements, String[] names, int[] arraySizes) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800252 validate();
Jason Sams70d4e502010-09-02 17:35:23 -0700253 return rsnElementCreate2(mContext, elements, names, arraySizes);
Jason Sams2e1872f2010-08-17 16:25:41 -0700254 }
255 native void rsnElementGetNativeData(int con, int id, int[] elementData);
256 synchronized void nElementGetNativeData(int id, int[] elementData) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800257 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700258 rsnElementGetNativeData(mContext, id, elementData);
259 }
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700260 native void rsnElementGetSubElements(int con, int id,
261 int[] IDs, String[] names, int[] arraySizes);
262 synchronized void nElementGetSubElements(int id, int[] IDs, String[] names, int[] arraySizes) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800263 validate();
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700264 rsnElementGetSubElements(mContext, id, IDs, names, arraySizes);
Jason Sams2e1872f2010-08-17 16:25:41 -0700265 }
Jason Sams768bc022009-09-21 19:41:04 -0700266
Jason Samsb109cc72013-01-07 18:20:12 -0800267 native int rsnTypeCreate(int con, int eid, int x, int y, int z, boolean mips, boolean faces, int yuv);
268 synchronized int nTypeCreate(int eid, int x, int y, int z, boolean mips, boolean faces, int yuv) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800269 validate();
Jason Samsb109cc72013-01-07 18:20:12 -0800270 return rsnTypeCreate(mContext, eid, x, y, z, mips, faces, yuv);
Jason Sams2e1872f2010-08-17 16:25:41 -0700271 }
Jason Sams2e1872f2010-08-17 16:25:41 -0700272 native void rsnTypeGetNativeData(int con, int id, int[] typeData);
273 synchronized void nTypeGetNativeData(int id, int[] typeData) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800274 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700275 rsnTypeGetNativeData(mContext, id, typeData);
276 }
Jason Sams768bc022009-09-21 19:41:04 -0700277
Jason Sams857d0c72011-11-23 15:02:15 -0800278 native int rsnAllocationCreateTyped(int con, int type, int mip, int usage, int pointer);
279 synchronized int nAllocationCreateTyped(int type, int mip, int usage, int pointer) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800280 validate();
Jason Sams857d0c72011-11-23 15:02:15 -0800281 return rsnAllocationCreateTyped(mContext, type, mip, usage, pointer);
Jason Sams2e1872f2010-08-17 16:25:41 -0700282 }
Jason Sams5476b452010-12-08 16:14:36 -0800283 native int rsnAllocationCreateFromBitmap(int con, int type, int mip, Bitmap bmp, int usage);
284 synchronized int nAllocationCreateFromBitmap(int type, int mip, Bitmap bmp, int usage) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800285 validate();
Jason Sams5476b452010-12-08 16:14:36 -0800286 return rsnAllocationCreateFromBitmap(mContext, type, mip, bmp, usage);
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700287 }
Tim Murraya3145512012-12-04 17:59:29 -0800288
289 native int rsnAllocationCreateBitmapBackedAllocation(int con, int type, int mip, Bitmap bmp, int usage);
290 synchronized int nAllocationCreateBitmapBackedAllocation(int type, int mip, Bitmap bmp, int usage) {
291 validate();
292 return rsnAllocationCreateBitmapBackedAllocation(mContext, type, mip, bmp, usage);
293 }
294
295
Jason Sams5476b452010-12-08 16:14:36 -0800296 native int rsnAllocationCubeCreateFromBitmap(int con, int type, int mip, Bitmap bmp, int usage);
297 synchronized int nAllocationCubeCreateFromBitmap(int type, int mip, Bitmap bmp, int usage) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800298 validate();
Jason Sams5476b452010-12-08 16:14:36 -0800299 return rsnAllocationCubeCreateFromBitmap(mContext, type, mip, bmp, usage);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800300 }
Jason Sams2e1872f2010-08-17 16:25:41 -0700301 native int rsnAllocationCreateBitmapRef(int con, int type, Bitmap bmp);
302 synchronized int nAllocationCreateBitmapRef(int type, Bitmap bmp) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800303 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700304 return rsnAllocationCreateBitmapRef(mContext, type, bmp);
305 }
Jason Sams5476b452010-12-08 16:14:36 -0800306 native int rsnAllocationCreateFromAssetStream(int con, int mips, int assetStream, int usage);
307 synchronized int nAllocationCreateFromAssetStream(int mips, int assetStream, int usage) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800308 validate();
Jason Sams5476b452010-12-08 16:14:36 -0800309 return rsnAllocationCreateFromAssetStream(mContext, mips, assetStream, usage);
310 }
311
Jason Sams4ef66502010-12-10 16:03:15 -0800312 native void rsnAllocationCopyToBitmap(int con, int alloc, Bitmap bmp);
313 synchronized void nAllocationCopyToBitmap(int alloc, Bitmap bmp) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800314 validate();
Jason Sams4ef66502010-12-10 16:03:15 -0800315 rsnAllocationCopyToBitmap(mContext, alloc, bmp);
316 }
317
318
Jason Sams5476b452010-12-08 16:14:36 -0800319 native void rsnAllocationSyncAll(int con, int alloc, int src);
320 synchronized void nAllocationSyncAll(int alloc, int src) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800321 validate();
Jason Sams5476b452010-12-08 16:14:36 -0800322 rsnAllocationSyncAll(mContext, alloc, src);
323 }
Jason Sams72226e02013-02-22 12:45:54 -0800324 native Surface rsnAllocationGetSurface(int con, int alloc);
325 synchronized Surface nAllocationGetSurface(int alloc) {
Jason Sams615e7ce2012-01-13 14:01:20 -0800326 validate();
Jason Sams72226e02013-02-22 12:45:54 -0800327 return rsnAllocationGetSurface(mContext, alloc);
Jason Samsfe1d5ff2012-03-23 11:47:26 -0700328 }
Jason Samsfb9aa9f2012-03-28 15:30:07 -0700329 native void rsnAllocationSetSurface(int con, int alloc, Surface sur);
330 synchronized void nAllocationSetSurface(int alloc, Surface sur) {
Jason Sams163766c2012-02-15 12:04:24 -0800331 validate();
Jason Samsfb9aa9f2012-03-28 15:30:07 -0700332 rsnAllocationSetSurface(mContext, alloc, sur);
Jason Sams163766c2012-02-15 12:04:24 -0800333 }
334 native void rsnAllocationIoSend(int con, int alloc);
335 synchronized void nAllocationIoSend(int alloc) {
336 validate();
337 rsnAllocationIoSend(mContext, alloc);
338 }
339 native void rsnAllocationIoReceive(int con, int alloc);
340 synchronized void nAllocationIoReceive(int alloc) {
341 validate();
342 rsnAllocationIoReceive(mContext, alloc);
343 }
344
Jason Sams615e7ce2012-01-13 14:01:20 -0800345
Jason Samsf7086092011-01-12 13:28:37 -0800346 native void rsnAllocationGenerateMipmaps(int con, int alloc);
347 synchronized void nAllocationGenerateMipmaps(int alloc) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800348 validate();
Jason Samsf7086092011-01-12 13:28:37 -0800349 rsnAllocationGenerateMipmaps(mContext, alloc);
350 }
Jason Sams4ef66502010-12-10 16:03:15 -0800351 native void rsnAllocationCopyFromBitmap(int con, int alloc, Bitmap bmp);
352 synchronized void nAllocationCopyFromBitmap(int alloc, Bitmap bmp) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800353 validate();
Jason Sams4ef66502010-12-10 16:03:15 -0800354 rsnAllocationCopyFromBitmap(mContext, alloc, bmp);
Jason Sams2e1872f2010-08-17 16:25:41 -0700355 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700356
Jason Sams49a05d72010-12-29 14:31:29 -0800357
358 native void rsnAllocationData1D(int con, int id, int off, int mip, int count, int[] d, int sizeBytes);
359 synchronized void nAllocationData1D(int id, int off, int mip, int count, int[] d, int sizeBytes) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800360 validate();
Jason Sams49a05d72010-12-29 14:31:29 -0800361 rsnAllocationData1D(mContext, id, off, mip, count, d, sizeBytes);
Jason Sams2e1872f2010-08-17 16:25:41 -0700362 }
Jason Sams49a05d72010-12-29 14:31:29 -0800363 native void rsnAllocationData1D(int con, int id, int off, int mip, int count, short[] d, int sizeBytes);
364 synchronized void nAllocationData1D(int id, int off, int mip, int count, short[] d, int sizeBytes) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800365 validate();
Jason Sams49a05d72010-12-29 14:31:29 -0800366 rsnAllocationData1D(mContext, id, off, mip, count, d, sizeBytes);
367 }
368 native void rsnAllocationData1D(int con, int id, int off, int mip, int count, byte[] d, int sizeBytes);
369 synchronized void nAllocationData1D(int id, int off, int mip, int count, byte[] d, int sizeBytes) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800370 validate();
Jason Sams49a05d72010-12-29 14:31:29 -0800371 rsnAllocationData1D(mContext, id, off, mip, count, d, sizeBytes);
372 }
373 native void rsnAllocationData1D(int con, int id, int off, int mip, int count, float[] d, int sizeBytes);
374 synchronized void nAllocationData1D(int id, int off, int mip, int count, float[] d, int sizeBytes) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800375 validate();
Jason Sams49a05d72010-12-29 14:31:29 -0800376 rsnAllocationData1D(mContext, id, off, mip, count, d, sizeBytes);
Jason Sams2e1872f2010-08-17 16:25:41 -0700377 }
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700378
Jason Sams49a05d72010-12-29 14:31:29 -0800379 native void rsnAllocationElementData1D(int con, int id, int xoff, int mip, int compIdx, byte[] d, int sizeBytes);
380 synchronized void nAllocationElementData1D(int id, int xoff, int mip, int compIdx, byte[] d, int sizeBytes) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800381 validate();
Jason Sams49a05d72010-12-29 14:31:29 -0800382 rsnAllocationElementData1D(mContext, id, xoff, mip, compIdx, d, sizeBytes);
Jason Sams2e1872f2010-08-17 16:25:41 -0700383 }
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700384
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700385 native void rsnAllocationData2D(int con,
386 int dstAlloc, int dstXoff, int dstYoff,
387 int dstMip, int dstFace,
388 int width, int height,
389 int srcAlloc, int srcXoff, int srcYoff,
390 int srcMip, int srcFace);
391 synchronized void nAllocationData2D(int dstAlloc, int dstXoff, int dstYoff,
392 int dstMip, int dstFace,
393 int width, int height,
394 int srcAlloc, int srcXoff, int srcYoff,
395 int srcMip, int srcFace) {
396 validate();
397 rsnAllocationData2D(mContext,
398 dstAlloc, dstXoff, dstYoff,
399 dstMip, dstFace,
400 width, height,
401 srcAlloc, srcXoff, srcYoff,
402 srcMip, srcFace);
403 }
404
Jason Samsfa445b92011-01-07 17:00:07 -0800405 native void rsnAllocationData2D(int con, int id, int xoff, int yoff, int mip, int face, int w, int h, byte[] d, int sizeBytes);
406 synchronized void nAllocationData2D(int id, int xoff, int yoff, int mip, int face, int w, int h, byte[] d, int sizeBytes) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800407 validate();
Jason Samsfa445b92011-01-07 17:00:07 -0800408 rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes);
409 }
410 native void rsnAllocationData2D(int con, int id, int xoff, int yoff, int mip, int face, int w, int h, short[] d, int sizeBytes);
411 synchronized void nAllocationData2D(int id, int xoff, int yoff, int mip, int face, int w, int h, short[] d, int sizeBytes) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800412 validate();
Jason Samsfa445b92011-01-07 17:00:07 -0800413 rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes);
414 }
Jason Sams49a05d72010-12-29 14:31:29 -0800415 native void rsnAllocationData2D(int con, int id, int xoff, int yoff, int mip, int face, int w, int h, int[] d, int sizeBytes);
416 synchronized void nAllocationData2D(int id, int xoff, int yoff, int mip, int face, int w, int h, int[] d, int sizeBytes) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800417 validate();
Jason Sams49a05d72010-12-29 14:31:29 -0800418 rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes);
Jason Sams2e1872f2010-08-17 16:25:41 -0700419 }
Jason Sams49a05d72010-12-29 14:31:29 -0800420 native void rsnAllocationData2D(int con, int id, int xoff, int yoff, int mip, int face, int w, int h, float[] d, int sizeBytes);
421 synchronized void nAllocationData2D(int id, int xoff, int yoff, int mip, int face, int w, int h, float[] d, int sizeBytes) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800422 validate();
Jason Sams49a05d72010-12-29 14:31:29 -0800423 rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes);
Jason Sams2e1872f2010-08-17 16:25:41 -0700424 }
Jason Samsfa445b92011-01-07 17:00:07 -0800425 native void rsnAllocationData2D(int con, int id, int xoff, int yoff, int mip, int face, Bitmap b);
426 synchronized void nAllocationData2D(int id, int xoff, int yoff, int mip, int face, Bitmap b) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800427 validate();
Jason Samsfa445b92011-01-07 17:00:07 -0800428 rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, b);
429 }
Jason Sams49a05d72010-12-29 14:31:29 -0800430
Jason Samsfa445b92011-01-07 17:00:07 -0800431 native void rsnAllocationRead(int con, int id, byte[] d);
432 synchronized void nAllocationRead(int id, byte[] d) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800433 validate();
Jason Samsfa445b92011-01-07 17:00:07 -0800434 rsnAllocationRead(mContext, id, d);
435 }
436 native void rsnAllocationRead(int con, int id, short[] d);
437 synchronized void nAllocationRead(int id, short[] d) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800438 validate();
Jason Samsfa445b92011-01-07 17:00:07 -0800439 rsnAllocationRead(mContext, id, d);
440 }
Jason Sams2e1872f2010-08-17 16:25:41 -0700441 native void rsnAllocationRead(int con, int id, int[] d);
442 synchronized void nAllocationRead(int id, int[] d) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800443 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700444 rsnAllocationRead(mContext, id, d);
445 }
446 native void rsnAllocationRead(int con, int id, float[] d);
447 synchronized void nAllocationRead(int id, float[] d) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800448 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700449 rsnAllocationRead(mContext, id, d);
450 }
Jason Sams2e1872f2010-08-17 16:25:41 -0700451 native int rsnAllocationGetType(int con, int id);
452 synchronized int nAllocationGetType(int id) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800453 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700454 return rsnAllocationGetType(mContext, id);
455 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700456
Jason Sams5edc6082010-10-05 13:32:49 -0700457 native void rsnAllocationResize1D(int con, int id, int dimX);
458 synchronized void nAllocationResize1D(int id, int dimX) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800459 validate();
Jason Sams5edc6082010-10-05 13:32:49 -0700460 rsnAllocationResize1D(mContext, id, dimX);
461 }
462 native void rsnAllocationResize2D(int con, int id, int dimX, int dimY);
463 synchronized void nAllocationResize2D(int id, int dimX, int dimY) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800464 validate();
Jason Sams5edc6082010-10-05 13:32:49 -0700465 rsnAllocationResize2D(mContext, id, dimX, dimY);
466 }
467
Jason Sams2e1872f2010-08-17 16:25:41 -0700468 native int rsnFileA3DCreateFromAssetStream(int con, int assetStream);
469 synchronized int nFileA3DCreateFromAssetStream(int assetStream) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800470 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700471 return rsnFileA3DCreateFromAssetStream(mContext, assetStream);
472 }
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800473 native int rsnFileA3DCreateFromFile(int con, String path);
474 synchronized int nFileA3DCreateFromFile(String path) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800475 validate();
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800476 return rsnFileA3DCreateFromFile(mContext, path);
477 }
478 native int rsnFileA3DCreateFromAsset(int con, AssetManager mgr, String path);
479 synchronized int nFileA3DCreateFromAsset(AssetManager mgr, String path) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800480 validate();
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800481 return rsnFileA3DCreateFromAsset(mContext, mgr, path);
482 }
Jason Sams2e1872f2010-08-17 16:25:41 -0700483 native int rsnFileA3DGetNumIndexEntries(int con, int fileA3D);
484 synchronized int nFileA3DGetNumIndexEntries(int fileA3D) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800485 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700486 return rsnFileA3DGetNumIndexEntries(mContext, fileA3D);
487 }
488 native void rsnFileA3DGetIndexEntries(int con, int fileA3D, int numEntries, int[] IDs, String[] names);
489 synchronized void nFileA3DGetIndexEntries(int fileA3D, int numEntries, int[] IDs, String[] names) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800490 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700491 rsnFileA3DGetIndexEntries(mContext, fileA3D, numEntries, IDs, names);
492 }
493 native int rsnFileA3DGetEntryByIndex(int con, int fileA3D, int index);
494 synchronized int nFileA3DGetEntryByIndex(int fileA3D, int index) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800495 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700496 return rsnFileA3DGetEntryByIndex(mContext, fileA3D, index);
497 }
Jason Samsbd1c3ad2009-08-03 16:03:08 -0700498
Alex Sakhartchouke27cdee2010-12-17 11:41:08 -0800499 native int rsnFontCreateFromFile(int con, String fileName, float size, int dpi);
500 synchronized int nFontCreateFromFile(String fileName, float size, int dpi) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800501 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700502 return rsnFontCreateFromFile(mContext, fileName, size, dpi);
503 }
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800504 native int rsnFontCreateFromAssetStream(int con, String name, float size, int dpi, int assetStream);
505 synchronized int nFontCreateFromAssetStream(String name, float size, int dpi, int assetStream) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800506 validate();
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800507 return rsnFontCreateFromAssetStream(mContext, name, size, dpi, assetStream);
508 }
509 native int rsnFontCreateFromAsset(int con, AssetManager mgr, String path, float size, int dpi);
510 synchronized int nFontCreateFromAsset(AssetManager mgr, String path, float size, int dpi) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800511 validate();
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800512 return rsnFontCreateFromAsset(mContext, mgr, path, size, dpi);
513 }
Jason Sams22534172009-08-04 16:58:20 -0700514
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700515
Jason Sams2e1872f2010-08-17 16:25:41 -0700516 native void rsnScriptBindAllocation(int con, int script, int alloc, int slot);
517 synchronized void nScriptBindAllocation(int script, int alloc, int slot) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800518 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700519 rsnScriptBindAllocation(mContext, script, alloc, slot);
520 }
521 native void rsnScriptSetTimeZone(int con, int script, byte[] timeZone);
522 synchronized void nScriptSetTimeZone(int script, byte[] timeZone) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800523 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700524 rsnScriptSetTimeZone(mContext, script, timeZone);
525 }
526 native void rsnScriptInvoke(int con, int id, int slot);
527 synchronized void nScriptInvoke(int id, int slot) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800528 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700529 rsnScriptInvoke(mContext, id, slot);
530 }
Jason Sams6e494d32011-04-27 16:33:11 -0700531 native void rsnScriptForEach(int con, int id, int slot, int ain, int aout, byte[] params);
532 native void rsnScriptForEach(int con, int id, int slot, int ain, int aout);
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800533 native void rsnScriptForEachClipped(int con, int id, int slot, int ain, int aout, byte[] params,
534 int xstart, int xend, int ystart, int yend, int zstart, int zend);
Stephen Hinesdac6ed02013-02-13 00:09:02 -0800535 native void rsnScriptForEachClipped(int con, int id, int slot, int ain, int aout,
536 int xstart, int xend, int ystart, int yend, int zstart, int zend);
Jason Sams6e494d32011-04-27 16:33:11 -0700537 synchronized void nScriptForEach(int id, int slot, int ain, int aout, byte[] params) {
538 validate();
539 if (params == null) {
540 rsnScriptForEach(mContext, id, slot, ain, aout);
541 } else {
542 rsnScriptForEach(mContext, id, slot, ain, aout, params);
543 }
544 }
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800545
546 synchronized void nScriptForEachClipped(int id, int slot, int ain, int aout, byte[] params,
547 int xstart, int xend, int ystart, int yend, int zstart, int zend) {
548 validate();
Stephen Hinesdac6ed02013-02-13 00:09:02 -0800549 if (params == null) {
550 rsnScriptForEachClipped(mContext, id, slot, ain, aout, xstart, xend, ystart, yend, zstart, zend);
551 } else {
552 rsnScriptForEachClipped(mContext, id, slot, ain, aout, params, xstart, xend, ystart, yend, zstart, zend);
553 }
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800554 }
555
Jason Sams2e1872f2010-08-17 16:25:41 -0700556 native void rsnScriptInvokeV(int con, int id, int slot, byte[] params);
557 synchronized void nScriptInvokeV(int id, int slot, byte[] params) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800558 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700559 rsnScriptInvokeV(mContext, id, slot, params);
560 }
561 native void rsnScriptSetVarI(int con, int id, int slot, int val);
562 synchronized void nScriptSetVarI(int id, int slot, int val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800563 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700564 rsnScriptSetVarI(mContext, id, slot, val);
565 }
Stephen Hines031ec58c2010-10-11 10:54:21 -0700566 native void rsnScriptSetVarJ(int con, int id, int slot, long val);
567 synchronized void nScriptSetVarJ(int id, int slot, long val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800568 validate();
Stephen Hines031ec58c2010-10-11 10:54:21 -0700569 rsnScriptSetVarJ(mContext, id, slot, val);
570 }
Jason Sams2e1872f2010-08-17 16:25:41 -0700571 native void rsnScriptSetVarF(int con, int id, int slot, float val);
572 synchronized void nScriptSetVarF(int id, int slot, float val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800573 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700574 rsnScriptSetVarF(mContext, id, slot, val);
575 }
Stephen Hinesca54ec32010-09-20 17:20:30 -0700576 native void rsnScriptSetVarD(int con, int id, int slot, double val);
577 synchronized void nScriptSetVarD(int id, int slot, double val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800578 validate();
Stephen Hinesca54ec32010-09-20 17:20:30 -0700579 rsnScriptSetVarD(mContext, id, slot, val);
580 }
Jason Sams2e1872f2010-08-17 16:25:41 -0700581 native void rsnScriptSetVarV(int con, int id, int slot, byte[] val);
582 synchronized void nScriptSetVarV(int id, int slot, byte[] val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800583 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700584 rsnScriptSetVarV(mContext, id, slot, val);
585 }
Stephen Hinesadeb8092012-04-20 14:26:06 -0700586 native void rsnScriptSetVarVE(int con, int id, int slot, byte[] val,
587 int e, int[] dims);
588 synchronized void nScriptSetVarVE(int id, int slot, byte[] val,
589 int e, int[] dims) {
590 validate();
591 rsnScriptSetVarVE(mContext, id, slot, val, e, dims);
592 }
Jason Sams6f4cf0b2010-11-16 17:37:02 -0800593 native void rsnScriptSetVarObj(int con, int id, int slot, int val);
594 synchronized void nScriptSetVarObj(int id, int slot, int val) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800595 validate();
Jason Sams6f4cf0b2010-11-16 17:37:02 -0800596 rsnScriptSetVarObj(mContext, id, slot, val);
597 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700598
Jason Samse4a06c52011-03-16 16:29:28 -0700599 native int rsnScriptCCreate(int con, String resName, String cacheDir,
600 byte[] script, int length);
601 synchronized int nScriptCCreate(String resName, String cacheDir, byte[] script, int length) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800602 validate();
Jason Samse4a06c52011-03-16 16:29:28 -0700603 return rsnScriptCCreate(mContext, resName, cacheDir, script, length);
Jason Sams2e1872f2010-08-17 16:25:41 -0700604 }
Jason Samsebfb4362009-09-23 13:57:02 -0700605
Jason Sams6ab97682012-08-10 12:09:43 -0700606 native int rsnScriptIntrinsicCreate(int con, int id, int eid);
607 synchronized int nScriptIntrinsicCreate(int id, int eid) {
608 validate();
609 return rsnScriptIntrinsicCreate(mContext, id, eid);
610 }
611
Jason Sams08a81582012-09-18 12:32:10 -0700612 native int rsnScriptKernelIDCreate(int con, int sid, int slot, int sig);
613 synchronized int nScriptKernelIDCreate(int sid, int slot, int sig) {
614 validate();
615 return rsnScriptKernelIDCreate(mContext, sid, slot, sig);
616 }
617
618 native int rsnScriptFieldIDCreate(int con, int sid, int slot);
619 synchronized int nScriptFieldIDCreate(int sid, int slot) {
620 validate();
621 return rsnScriptFieldIDCreate(mContext, sid, slot);
622 }
623
624 native int rsnScriptGroupCreate(int con, int[] kernels, int[] src, int[] dstk, int[] dstf, int[] types);
625 synchronized int nScriptGroupCreate(int[] kernels, int[] src, int[] dstk, int[] dstf, int[] types) {
626 validate();
627 return rsnScriptGroupCreate(mContext, kernels, src, dstk, dstf, types);
628 }
629
630 native void rsnScriptGroupSetInput(int con, int group, int kernel, int alloc);
631 synchronized void nScriptGroupSetInput(int group, int kernel, int alloc) {
632 validate();
633 rsnScriptGroupSetInput(mContext, group, kernel, alloc);
634 }
635
636 native void rsnScriptGroupSetOutput(int con, int group, int kernel, int alloc);
637 synchronized void nScriptGroupSetOutput(int group, int kernel, int alloc) {
638 validate();
639 rsnScriptGroupSetOutput(mContext, group, kernel, alloc);
640 }
641
642 native void rsnScriptGroupExecute(int con, int group);
643 synchronized void nScriptGroupExecute(int group) {
644 validate();
645 rsnScriptGroupExecute(mContext, group);
646 }
647
Alex Sakhartchouka89094a2011-05-04 17:45:36 -0700648 native int rsnSamplerCreate(int con, int magFilter, int minFilter,
649 int wrapS, int wrapT, int wrapR, float aniso);
650 synchronized int nSamplerCreate(int magFilter, int minFilter,
651 int wrapS, int wrapT, int wrapR, float aniso) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800652 validate();
Alex Sakhartchouka89094a2011-05-04 17:45:36 -0700653 return rsnSamplerCreate(mContext, magFilter, minFilter, wrapS, wrapT, wrapR, aniso);
Jason Sams2e1872f2010-08-17 16:25:41 -0700654 }
Jason Sams0011bcf2009-12-15 12:58:36 -0800655
Jason Sams331bf9b2011-04-06 11:23:54 -0700656 native int rsnProgramStoreCreate(int con, boolean r, boolean g, boolean b, boolean a,
657 boolean depthMask, boolean dither,
658 int srcMode, int dstMode, int depthFunc);
659 synchronized int nProgramStoreCreate(boolean r, boolean g, boolean b, boolean a,
660 boolean depthMask, boolean dither,
661 int srcMode, int dstMode, int depthFunc) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800662 validate();
Jason Samsbd184c52011-04-06 11:44:47 -0700663 return rsnProgramStoreCreate(mContext, r, g, b, a, depthMask, dither, srcMode,
664 dstMode, depthFunc);
Jason Sams2e1872f2010-08-17 16:25:41 -0700665 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700666
Jason Sams94aaed32011-09-23 14:18:53 -0700667 native int rsnProgramRasterCreate(int con, boolean pointSprite, int cullMode);
668 synchronized int nProgramRasterCreate(boolean pointSprite, int cullMode) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800669 validate();
Jason Sams94aaed32011-09-23 14:18:53 -0700670 return rsnProgramRasterCreate(mContext, pointSprite, cullMode);
Jason Sams2e1872f2010-08-17 16:25:41 -0700671 }
Jason Sams1fe9b8c2009-06-11 14:46:10 -0700672
Jason Sams2e1872f2010-08-17 16:25:41 -0700673 native void rsnProgramBindConstants(int con, int pv, int slot, int mID);
674 synchronized void nProgramBindConstants(int pv, int slot, int mID) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800675 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700676 rsnProgramBindConstants(mContext, pv, slot, mID);
677 }
678 native void rsnProgramBindTexture(int con, int vpf, int slot, int a);
679 synchronized void nProgramBindTexture(int vpf, int slot, int a) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800680 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700681 rsnProgramBindTexture(mContext, vpf, slot, a);
682 }
683 native void rsnProgramBindSampler(int con, int vpf, int slot, int s);
684 synchronized void nProgramBindSampler(int vpf, int slot, int s) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800685 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700686 rsnProgramBindSampler(mContext, vpf, slot, s);
687 }
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800688 native int rsnProgramFragmentCreate(int con, String shader, String[] texNames, int[] params);
689 synchronized int nProgramFragmentCreate(String shader, String[] texNames, int[] params) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800690 validate();
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800691 return rsnProgramFragmentCreate(mContext, shader, texNames, params);
Jason Sams2e1872f2010-08-17 16:25:41 -0700692 }
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800693 native int rsnProgramVertexCreate(int con, String shader, String[] texNames, int[] params);
694 synchronized int nProgramVertexCreate(String shader, String[] texNames, int[] params) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800695 validate();
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800696 return rsnProgramVertexCreate(mContext, shader, texNames, params);
Jason Sams2e1872f2010-08-17 16:25:41 -0700697 }
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -0700698
Alex Sakhartchouk25999a02011-05-12 10:38:03 -0700699 native int rsnMeshCreate(int con, int[] vtx, int[] idx, int[] prim);
700 synchronized int nMeshCreate(int[] vtx, int[] idx, int[] prim) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800701 validate();
Alex Sakhartchouk25999a02011-05-12 10:38:03 -0700702 return rsnMeshCreate(mContext, vtx, idx, prim);
Alex Sakhartchouk9d71e212010-11-08 15:10:52 -0800703 }
Jason Sams2e1872f2010-08-17 16:25:41 -0700704 native int rsnMeshGetVertexBufferCount(int con, int id);
705 synchronized int nMeshGetVertexBufferCount(int id) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800706 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700707 return rsnMeshGetVertexBufferCount(mContext, id);
708 }
709 native int rsnMeshGetIndexCount(int con, int id);
710 synchronized int nMeshGetIndexCount(int id) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800711 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700712 return rsnMeshGetIndexCount(mContext, id);
713 }
714 native void rsnMeshGetVertices(int con, int id, int[] vtxIds, int vtxIdCount);
715 synchronized void nMeshGetVertices(int id, int[] vtxIds, int vtxIdCount) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800716 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700717 rsnMeshGetVertices(mContext, id, vtxIds, vtxIdCount);
718 }
719 native void rsnMeshGetIndices(int con, int id, int[] idxIds, int[] primitives, int vtxIdCount);
720 synchronized void nMeshGetIndices(int id, int[] idxIds, int[] primitives, int vtxIdCount) {
Jason Samsd1ac9812011-01-18 18:12:26 -0800721 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -0700722 rsnMeshGetIndices(mContext, id, idxIds, primitives, vtxIdCount);
723 }
724
Jason Samsf15ed012011-10-31 13:23:43 -0700725 native int rsnPathCreate(int con, int prim, boolean isStatic, int vtx, int loop, float q);
726 synchronized int nPathCreate(int prim, boolean isStatic, int vtx, int loop, float q) {
727 validate();
728 return rsnPathCreate(mContext, prim, isStatic, vtx, loop, q);
729 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700730
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800731 int mDev;
732 int mContext;
Romain Guy650a3eb2009-08-31 14:06:43 -0700733 @SuppressWarnings({"FieldCanBeLocal"})
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800734 MessageThread mMessageThread;
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700735
Jason Sams8cb39de2010-06-01 15:47:01 -0700736 Element mElement_U8;
737 Element mElement_I8;
738 Element mElement_U16;
739 Element mElement_I16;
740 Element mElement_U32;
741 Element mElement_I32;
Stephen Hines52d83632010-10-11 16:10:42 -0700742 Element mElement_U64;
Stephen Hinesef1dac22010-10-01 15:39:33 -0700743 Element mElement_I64;
Jason Sams8cb39de2010-06-01 15:47:01 -0700744 Element mElement_F32;
Stephen Hines02f417052010-09-30 15:19:22 -0700745 Element mElement_F64;
Jason Samsf110d4b2010-06-21 17:42:41 -0700746 Element mElement_BOOLEAN;
Jason Sams3c0dfba2009-09-27 17:50:38 -0700747
Jason Sams8cb39de2010-06-01 15:47:01 -0700748 Element mElement_ELEMENT;
749 Element mElement_TYPE;
750 Element mElement_ALLOCATION;
751 Element mElement_SAMPLER;
752 Element mElement_SCRIPT;
753 Element mElement_MESH;
754 Element mElement_PROGRAM_FRAGMENT;
755 Element mElement_PROGRAM_VERTEX;
756 Element mElement_PROGRAM_RASTER;
757 Element mElement_PROGRAM_STORE;
Stephen Hines3a291412012-04-11 17:27:29 -0700758 Element mElement_FONT;
Jason Samsa70f4162010-03-26 15:33:42 -0700759
Jason Sams3c0dfba2009-09-27 17:50:38 -0700760 Element mElement_A_8;
761 Element mElement_RGB_565;
762 Element mElement_RGB_888;
763 Element mElement_RGBA_5551;
764 Element mElement_RGBA_4444;
765 Element mElement_RGBA_8888;
766
Jason Sams8cb39de2010-06-01 15:47:01 -0700767 Element mElement_FLOAT_2;
768 Element mElement_FLOAT_3;
769 Element mElement_FLOAT_4;
Stephen Hines836c4a52011-06-01 14:38:10 -0700770
771 Element mElement_DOUBLE_2;
772 Element mElement_DOUBLE_3;
773 Element mElement_DOUBLE_4;
774
775 Element mElement_UCHAR_2;
776 Element mElement_UCHAR_3;
Jason Sams8cb39de2010-06-01 15:47:01 -0700777 Element mElement_UCHAR_4;
Jason Sams7d787b42009-11-15 12:14:26 -0800778
Stephen Hines836c4a52011-06-01 14:38:10 -0700779 Element mElement_CHAR_2;
780 Element mElement_CHAR_3;
781 Element mElement_CHAR_4;
782
783 Element mElement_USHORT_2;
784 Element mElement_USHORT_3;
785 Element mElement_USHORT_4;
786
787 Element mElement_SHORT_2;
788 Element mElement_SHORT_3;
789 Element mElement_SHORT_4;
790
791 Element mElement_UINT_2;
792 Element mElement_UINT_3;
793 Element mElement_UINT_4;
794
795 Element mElement_INT_2;
796 Element mElement_INT_3;
797 Element mElement_INT_4;
798
799 Element mElement_ULONG_2;
800 Element mElement_ULONG_3;
801 Element mElement_ULONG_4;
802
803 Element mElement_LONG_2;
804 Element mElement_LONG_3;
805 Element mElement_LONG_4;
806
Jason Sams1d45c472010-08-25 14:31:48 -0700807 Element mElement_MATRIX_4X4;
808 Element mElement_MATRIX_3X3;
809 Element mElement_MATRIX_2X2;
810
Jason Sams4d339932010-05-11 14:03:58 -0700811 Sampler mSampler_CLAMP_NEAREST;
812 Sampler mSampler_CLAMP_LINEAR;
813 Sampler mSampler_CLAMP_LINEAR_MIP_LINEAR;
814 Sampler mSampler_WRAP_NEAREST;
815 Sampler mSampler_WRAP_LINEAR;
816 Sampler mSampler_WRAP_LINEAR_MIP_LINEAR;
Tim Murray6b9b2ca2013-02-15 13:25:55 -0800817 Sampler mSampler_MIRRORED_REPEAT_NEAREST;
818 Sampler mSampler_MIRRORED_REPEAT_LINEAR;
819 Sampler mSampler_MIRRORED_REPEAT_LINEAR_MIP_LINEAR;
Jason Sams4d339932010-05-11 14:03:58 -0700820
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700821 ProgramStore mProgramStore_BLEND_NONE_DEPTH_TEST;
822 ProgramStore mProgramStore_BLEND_NONE_DEPTH_NO_DEPTH;
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700823 ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_TEST;
824 ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_NO_DEPTH;
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700825
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700826 ProgramRaster mProgramRaster_CULL_BACK;
827 ProgramRaster mProgramRaster_CULL_FRONT;
828 ProgramRaster mProgramRaster_CULL_NONE;
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700829
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700830 ///////////////////////////////////////////////////////////////////////////////////
Jack Palevich43702d82009-05-28 13:38:16 -0700831 //
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700832
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700833 /**
Jason Sams27676fe2010-11-10 17:00:59 -0800834 * Base class application should derive from for handling RS messages
Stephen Hines8cecbb52011-02-28 18:20:34 -0800835 * coming from their scripts. When a script calls sendToClient the data
Jason Sams27676fe2010-11-10 17:00:59 -0800836 * fields will be filled in and then the run method called by a message
837 * handling thread. This will occur some time after sendToClient completes
838 * in the script.
839 *
840 */
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800841 public static class RSMessageHandler implements Runnable {
Jason Sams516c3192009-10-06 13:58:47 -0700842 protected int[] mData;
843 protected int mID;
Jason Sams1c415172010-11-08 17:06:46 -0800844 protected int mLength;
Jason Sams516c3192009-10-06 13:58:47 -0700845 public void run() {
846 }
847 }
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700848 /**
Jason Sams27676fe2010-11-10 17:00:59 -0800849 * If an application is expecting messages it should set this field to an
850 * instance of RSMessage. This instance will receive all the user messages
851 * sent from sendToClient by scripts from this context.
852 *
853 */
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800854 RSMessageHandler mMessageCallback = null;
855
856 public void setMessageHandler(RSMessageHandler msg) {
857 mMessageCallback = msg;
858 }
859 public RSMessageHandler getMessageHandler() {
860 return mMessageCallback;
861 }
Jason Sams516c3192009-10-06 13:58:47 -0700862
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700863 /**
Jason Sams455d6442013-02-05 19:20:18 -0800864 * @hide
865 *
866 * @param id
867 * @param data
868 */
869 public void sendMessage(int id, int[] data) {
870 nContextSendMessage(id, data);
871 }
872
873 /**
Jason Sams27676fe2010-11-10 17:00:59 -0800874 * Runtime error base class. An application should derive from this class
875 * if it wishes to install an error handler. When errors occur at runtime
876 * the fields in this class will be filled and the run method called.
877 *
878 */
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800879 public static class RSErrorHandler implements Runnable {
Jason Sams1c415172010-11-08 17:06:46 -0800880 protected String mErrorMessage;
881 protected int mErrorNum;
882 public void run() {
883 }
884 }
Jason Sams27676fe2010-11-10 17:00:59 -0800885
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700886 /**
Jason Sams27676fe2010-11-10 17:00:59 -0800887 * Application Error handler. All runtime errors will be dispatched to the
888 * instance of RSAsyncError set here. If this field is null a
889 * RSRuntimeException will instead be thrown with details about the error.
890 * This will cause program termaination.
891 *
892 */
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800893 RSErrorHandler mErrorCallback = null;
894
895 public void setErrorHandler(RSErrorHandler msg) {
896 mErrorCallback = msg;
897 }
898 public RSErrorHandler getErrorHandler() {
899 return mErrorCallback;
900 }
Jason Sams1c415172010-11-08 17:06:46 -0800901
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700902 /**
Jason Sams27676fe2010-11-10 17:00:59 -0800903 * RenderScript worker threads priority enumeration. The default value is
904 * NORMAL. Applications wishing to do background processing such as
905 * wallpapers should set their priority to LOW to avoid starving forground
906 * processes.
907 */
Jason Sams7d787b42009-11-15 12:14:26 -0800908 public enum Priority {
Glenn Kasten260c77a2011-06-01 17:25:54 -0700909 LOW (Process.THREAD_PRIORITY_BACKGROUND + (5 * Process.THREAD_PRIORITY_LESS_FAVORABLE)),
910 NORMAL (Process.THREAD_PRIORITY_DISPLAY);
Jason Sams7d787b42009-11-15 12:14:26 -0800911
912 int mID;
913 Priority(int id) {
914 mID = id;
915 }
916 }
917
Jason Sams771bebb2009-12-07 12:40:12 -0800918 void validate() {
919 if (mContext == 0) {
Jason Samsc1d62102010-11-04 14:32:19 -0700920 throw new RSInvalidStateException("Calling RS with no Context active.");
Jason Sams771bebb2009-12-07 12:40:12 -0800921 }
922 }
923
Jason Sams27676fe2010-11-10 17:00:59 -0800924
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700925 /**
Jason Sams27676fe2010-11-10 17:00:59 -0800926 * Change the priority of the worker threads for this context.
927 *
928 * @param p New priority to be set.
929 */
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800930 public void setPriority(Priority p) {
Jason Sams5dbfe932010-01-27 14:41:43 -0800931 validate();
Jason Sams7d787b42009-11-15 12:14:26 -0800932 nContextSetPriority(p.mID);
933 }
934
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800935 static class MessageThread extends Thread {
Jason Sams516c3192009-10-06 13:58:47 -0700936 RenderScript mRS;
937 boolean mRun = true;
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800938 int[] mAuxData = new int[2];
Jason Sams1c415172010-11-08 17:06:46 -0800939
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800940 static final int RS_MESSAGE_TO_CLIENT_NONE = 0;
941 static final int RS_MESSAGE_TO_CLIENT_EXCEPTION = 1;
942 static final int RS_MESSAGE_TO_CLIENT_RESIZE = 2;
943 static final int RS_MESSAGE_TO_CLIENT_ERROR = 3;
944 static final int RS_MESSAGE_TO_CLIENT_USER = 4;
Jason Sams516c3192009-10-06 13:58:47 -0700945
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800946 static final int RS_ERROR_FATAL_UNKNOWN = 0x1000;
Jason Samsadd9d962010-11-22 16:20:16 -0800947
Jason Sams516c3192009-10-06 13:58:47 -0700948 MessageThread(RenderScript rs) {
949 super("RSMessageThread");
950 mRS = rs;
951
952 }
953
954 public void run() {
955 // This function is a temporary solution. The final solution will
956 // used typed allocations where the message id is the type indicator.
957 int[] rbuf = new int[16];
Jason Sams2e1872f2010-08-17 16:25:41 -0700958 mRS.nContextInitToClient(mRS.mContext);
Jason Sams516c3192009-10-06 13:58:47 -0700959 while(mRun) {
Jason Sams1d45c472010-08-25 14:31:48 -0700960 rbuf[0] = 0;
Jason Samsedbfabd2011-05-17 15:01:29 -0700961 int msg = mRS.nContextPeekMessage(mRS.mContext, mAuxData);
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800962 int size = mAuxData[1];
963 int subID = mAuxData[0];
Jason Sams1c415172010-11-08 17:06:46 -0800964
965 if (msg == RS_MESSAGE_TO_CLIENT_USER) {
966 if ((size>>2) >= rbuf.length) {
967 rbuf = new int[(size + 3) >> 2];
968 }
Jason Samsedbfabd2011-05-17 15:01:29 -0700969 if (mRS.nContextGetUserMessage(mRS.mContext, rbuf) !=
970 RS_MESSAGE_TO_CLIENT_USER) {
971 throw new RSDriverException("Error processing message from Renderscript.");
972 }
Jason Sams1c415172010-11-08 17:06:46 -0800973
974 if(mRS.mMessageCallback != null) {
975 mRS.mMessageCallback.mData = rbuf;
976 mRS.mMessageCallback.mID = subID;
977 mRS.mMessageCallback.mLength = size;
978 mRS.mMessageCallback.run();
Jason Sams1d45c472010-08-25 14:31:48 -0700979 } else {
Jason Sams1c415172010-11-08 17:06:46 -0800980 throw new RSInvalidStateException("Received a message from the script with no message handler installed.");
Jason Sams516c3192009-10-06 13:58:47 -0700981 }
Stephen Hinesab98bb62010-09-24 14:38:30 -0700982 continue;
Jason Sams516c3192009-10-06 13:58:47 -0700983 }
Jason Sams1c415172010-11-08 17:06:46 -0800984
985 if (msg == RS_MESSAGE_TO_CLIENT_ERROR) {
986 String e = mRS.nContextGetErrorMessage(mRS.mContext);
987
Jason Samsadd9d962010-11-22 16:20:16 -0800988 if (subID >= RS_ERROR_FATAL_UNKNOWN) {
989 throw new RSRuntimeException("Fatal error " + subID + ", details: " + e);
990 }
991
Jason Sams1c415172010-11-08 17:06:46 -0800992 if(mRS.mErrorCallback != null) {
993 mRS.mErrorCallback.mErrorMessage = e;
994 mRS.mErrorCallback.mErrorNum = subID;
995 mRS.mErrorCallback.run();
996 } else {
Jason Samsa4b7bc92013-02-05 15:05:39 -0800997 android.util.Log.e(LOG_TAG, "non fatal RS error, " + e);
Stephen Hinesbe74bdd2012-02-03 15:29:36 -0800998 // Do not throw here. In these cases, we do not have
999 // a fatal error.
Jason Sams1c415172010-11-08 17:06:46 -08001000 }
1001 continue;
1002 }
1003
1004 // 2: teardown.
1005 // But we want to avoid starving other threads during
1006 // teardown by yielding until the next line in the destructor
1007 // can execute to set mRun = false
1008 try {
1009 sleep(1, 0);
1010 } catch(InterruptedException e) {
Jason Sams516c3192009-10-06 13:58:47 -07001011 }
Jason Sams516c3192009-10-06 13:58:47 -07001012 }
Jason Sams3bc47d42009-11-12 15:10:25 -08001013 Log.d(LOG_TAG, "MessageThread exiting.");
Jason Sams516c3192009-10-06 13:58:47 -07001014 }
1015 }
1016
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001017 RenderScript(Context ctx) {
Jason Sams1a4e1f32012-02-24 17:51:24 -08001018 if (ctx != null) {
1019 mApplicationContext = ctx.getApplicationContext();
1020 }
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001021 }
1022
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001023 /**
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001024 * Gets the application context associated with the RenderScript context.
1025 *
1026 * @return The application context.
1027 */
1028 public final Context getApplicationContext() {
1029 return mApplicationContext;
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001030 }
1031
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001032 /**
Jason Samsadd26dc2013-02-22 18:43:45 -08001033 * @hide
1034 */
1035 public static RenderScript create(Context ctx, int sdkVersion) {
1036 return create(ctx, sdkVersion, ContextType.NORMAL);
1037 }
1038
1039 /**
Jason Sams27676fe2010-11-10 17:00:59 -08001040 * Create a basic RenderScript context.
1041 *
Jason Sams1a4e1f32012-02-24 17:51:24 -08001042 * @hide
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001043 * @param ctx The context.
Jason Sams27676fe2010-11-10 17:00:59 -08001044 * @return RenderScript
1045 */
Jason Samsadd26dc2013-02-22 18:43:45 -08001046 public static RenderScript create(Context ctx, int sdkVersion, ContextType ct) {
Dan Morrille4d9a012013-03-28 18:10:43 -07001047 if (!sInitialized) {
1048 Log.e(LOG_TAG, "RenderScript.create() called when disabled; someone is likely to crash");
1049 return null;
1050 }
1051
Shih-wei Liao6b32fab2010-12-10 01:03:59 -08001052 RenderScript rs = new RenderScript(ctx);
Jason Sams704ff642010-02-09 16:05:07 -08001053
1054 rs.mDev = rs.nDeviceCreate();
Jason Samsadd26dc2013-02-22 18:43:45 -08001055 rs.mContext = rs.nContextCreate(rs.mDev, 0, sdkVersion, ct.mID);
Jason Sams26985362011-05-03 15:01:58 -07001056 if (rs.mContext == 0) {
1057 throw new RSDriverException("Failed to create RS context.");
1058 }
Jason Sams704ff642010-02-09 16:05:07 -08001059 rs.mMessageThread = new MessageThread(rs);
1060 rs.mMessageThread.start();
Jason Sams704ff642010-02-09 16:05:07 -08001061 return rs;
Jason Samsefd9b6fb2009-11-03 13:58:36 -08001062 }
1063
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001064 /**
Jason Sams1a4e1f32012-02-24 17:51:24 -08001065 * Create a basic RenderScript context.
1066 *
1067 * @param ctx The context.
1068 * @return RenderScript
1069 */
1070 public static RenderScript create(Context ctx) {
Jason Samsadd26dc2013-02-22 18:43:45 -08001071 return create(ctx, ContextType.NORMAL);
1072 }
1073
1074 /**
1075 * Create a basic RenderScript context.
1076 *
1077 * @hide
1078 *
1079 * @param ctx The context.
1080 * @return RenderScript
1081 */
1082 public static RenderScript create(Context ctx, ContextType ct) {
Jason Sams1a4e1f32012-02-24 17:51:24 -08001083 int v = ctx.getApplicationInfo().targetSdkVersion;
Jason Samsadd26dc2013-02-22 18:43:45 -08001084 return create(ctx, v, ct);
Jason Sams1a4e1f32012-02-24 17:51:24 -08001085 }
1086
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001087 /**
Jason Sams27676fe2010-11-10 17:00:59 -08001088 * Print the currently available debugging information about the state of
1089 * the RS context to the log.
1090 *
Jason Sams27676fe2010-11-10 17:00:59 -08001091 */
Jason Samsbf6ef8d2010-12-06 15:59:59 -08001092 public void contextDump() {
Jason Sams5dbfe932010-01-27 14:41:43 -08001093 validate();
Jason Samsbf6ef8d2010-12-06 15:59:59 -08001094 nContextDump(0);
Jason Sams715333b2009-11-17 17:26:46 -08001095 }
1096
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001097 /**
Jason Sams27676fe2010-11-10 17:00:59 -08001098 * Wait for any commands in the fifo between the java bindings and native to
1099 * be processed.
1100 *
1101 */
Jason Sams96ed4cf2010-06-15 12:15:57 -07001102 public void finish() {
1103 nContextFinish();
1104 }
1105
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -07001106 /**
Jason Sams27676fe2010-11-10 17:00:59 -08001107 * Destroy this renderscript context. Once this function is called its no
1108 * longer legal to use this or any objects created by this context.
1109 *
1110 */
Jason Samsf5b45962009-08-25 14:49:07 -07001111 public void destroy() {
Jason Sams5dbfe932010-01-27 14:41:43 -08001112 validate();
Jason Sams2e1872f2010-08-17 16:25:41 -07001113 nContextDeinitToClient(mContext);
Jason Sams516c3192009-10-06 13:58:47 -07001114 mMessageThread.mRun = false;
Jason Samsa8bf9422010-09-16 13:43:19 -07001115 try {
1116 mMessageThread.join();
1117 } catch(InterruptedException e) {
1118 }
Jason Sams516c3192009-10-06 13:58:47 -07001119
Jason Sams2e1872f2010-08-17 16:25:41 -07001120 nContextDestroy();
Jason Samsf5b45962009-08-25 14:49:07 -07001121 mContext = 0;
1122
1123 nDeviceDestroy(mDev);
1124 mDev = 0;
1125 }
Jason Sams02fb2cb2009-05-28 15:37:57 -07001126
Jason Samsa9e7a052009-09-25 14:51:22 -07001127 boolean isAlive() {
1128 return mContext != 0;
1129 }
1130
Jason Samsbf6ef8d2010-12-06 15:59:59 -08001131 int safeID(BaseObj o) {
Jason Sams6b9dec02009-09-23 16:38:37 -07001132 if(o != null) {
Jason Samse07694b2012-04-03 15:36:36 -07001133 return o.getID(this);
Jason Samsd8e41612009-08-20 17:22:40 -07001134 }
Jason Sams6b9dec02009-09-23 16:38:37 -07001135 return 0;
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001136 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001137}