RenderScript.java revision ff7256e757502279b1777127a12eba235be679ae
160aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich/*
2be74bdd2349095f203ae0fddcc4816bfbd56bc5dStephen Hines * Copyright (C) 2008-2012 The Android Open Source Project
360aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich *
460aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich * Licensed under the Apache License, Version 2.0 (the "License");
560aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich * you may not use this file except in compliance with the License.
660aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich * You may obtain a copy of the License at
760aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich *
860aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich *      http://www.apache.org/licenses/LICENSE-2.0
960aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich *
1060aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich * Unless required by applicable law or agreed to in writing, software
1160aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich * distributed under the License is distributed on an "AS IS" BASIS,
1260aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1360aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich * See the License for the specific language governing permissions and
1460aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich * limitations under the License.
1560aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich */
1660aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
1794d8e90ad78ee1dbc0efa315117688abd126ae55Jason Samspackage android.renderscript;
1860aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
19a6f338ca5f0c8359d1952167858851dd025e47e2Jason Samsimport java.io.File;
20fe1d5ffd1b6c4977a9f301997d2ad90e5b049a3bJason Samsimport java.lang.reflect.Field;
212f2472c42be8e80f00019594036744d902e09dcbTim Murrayimport java.lang.reflect.Method;
22ff7256e757502279b1777127a12eba235be679aeJason Samsimport java.util.concurrent.locks.ReentrantReadWriteLock;
2336e612a488511940b61f09803b270aa1c61b68e0Jason Sams
246b32fab1dbfd8bc1cc176557fe0a7b2ebd4966bdShih-wei Liaoimport android.content.Context;
254382467a80dd12c6362d57edca7f2367f7ae877cStephen Hinesimport android.content.pm.ApplicationInfo;
264382467a80dd12c6362d57edca7f2367f7ae877cStephen Hinesimport android.content.pm.PackageManager;
27b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchoukimport android.content.res.AssetManager;
28b8c5a84e7c23746a3fc26013e0880d3d95ca6588Jason Samsimport android.graphics.Bitmap;
29650a3eb7d621dc8e81573142a4498bbd07bcde27Romain Guyimport android.graphics.BitmapFactory;
30faa32b33b50ad941f631716dd0915e936bdc3ac5Jason Samsimport android.graphics.SurfaceTexture;
31260c77a4f741c3db76057cc4ea2ee54fe335ecf9Glenn Kastenimport android.os.Process;
3236e612a488511940b61f09803b270aa1c61b68e0Jason Samsimport android.util.Log;
3336e612a488511940b61f09803b270aa1c61b68e0Jason Samsimport android.view.Surface;
34e4d9a01bfc7451afff1ed399a5801c7aa2af2831Dan Morrillimport android.os.SystemProperties;
356d7a53cbddbffba30f7e9f82ced9c1ab46214f5aTim Murrayimport android.os.Trace;
364382467a80dd12c6362d57edca7f2367f7ae877cStephen Hines
379c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines/**
38c11e25c4e653124def1fb18e203b894f42106cbeTim Murray * This class provides access to a RenderScript context, which controls RenderScript
39c11e25c4e653124def1fb18e203b894f42106cbeTim Murray * initialization, resource management, and teardown. An instance of the RenderScript
40c11e25c4e653124def1fb18e203b894f42106cbeTim Murray * class must be created before any other RS objects can be created.
4127676fe24be7444a174c15df476e49adc5335d03Jason Sams *
423aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <div class="special reference">
433aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <h3>Developer Guides</h3>
44c11e25c4e653124def1fb18e203b894f42106cbeTim Murray * <p>For more information about creating an application that uses RenderScript, read the
45c11e25c4e653124def1fb18e203b894f42106cbeTim Murray * <a href="{@docRoot}guide/topics/renderscript/index.html">RenderScript</a> developer guide.</p>
463aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * </div>
47e29d471e5ca9781d8772d445ec7832e94856fd14Jason Sams **/
4860aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevichpublic class RenderScript {
496d7a53cbddbffba30f7e9f82ced9c1ab46214f5aTim Murray    static final long TRACE_TAG = Trace.TRACE_TAG_RS;
506d7a53cbddbffba30f7e9f82ced9c1ab46214f5aTim Murray
513bc47d438171dce294e816366d53bc9eca772c5bJason Sams    static final String LOG_TAG = "RenderScript_jni";
52bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    static final boolean DEBUG  = false;
53650a3eb7d621dc8e81573142a4498bbd07bcde27Romain Guy    @SuppressWarnings({"UnusedDeclaration", "deprecation"})
5443a17654cf4bfe7f1ec22bd8b7b32daccdf27c09Joe Onorato    static final boolean LOG_ENABLED = false;
5560aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
566b32fab1dbfd8bc1cc176557fe0a7b2ebd4966bdShih-wei Liao    private Context mApplicationContext;
5760aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
586b32fab1dbfd8bc1cc176557fe0a7b2ebd4966bdShih-wei Liao    /*
5960aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich     * We use a class initializer to allow the native code to cache some
6060aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich     * field offsets.
6160aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich     */
62e4d9a01bfc7451afff1ed399a5801c7aa2af2831Dan Morrill    @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"}) // TODO: now used locally; remove?
63bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    static boolean sInitialized;
64bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    native static void _nInit();
6560aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
662f2472c42be8e80f00019594036744d902e09dcbTim Murray    static Object sRuntime;
672f2472c42be8e80f00019594036744d902e09dcbTim Murray    static Method registerNativeAllocation;
682f2472c42be8e80f00019594036744d902e09dcbTim Murray    static Method registerNativeFree;
69dba3ba5b5bf6026abceced921b1b0d231b0faefdJason Sams
7060aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich    static {
7160aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich        sInitialized = false;
72e4d9a01bfc7451afff1ed399a5801c7aa2af2831Dan Morrill        if (!SystemProperties.getBoolean("config.disable_renderscript", false)) {
73e4d9a01bfc7451afff1ed399a5801c7aa2af2831Dan Morrill            try {
742f2472c42be8e80f00019594036744d902e09dcbTim Murray                Class<?> vm_runtime = Class.forName("dalvik.system.VMRuntime");
752f2472c42be8e80f00019594036744d902e09dcbTim Murray                Method get_runtime = vm_runtime.getDeclaredMethod("getRuntime");
762f2472c42be8e80f00019594036744d902e09dcbTim Murray                sRuntime = get_runtime.invoke(null);
772f2472c42be8e80f00019594036744d902e09dcbTim Murray                registerNativeAllocation = vm_runtime.getDeclaredMethod("registerNativeAllocation", Integer.TYPE);
782f2472c42be8e80f00019594036744d902e09dcbTim Murray                registerNativeFree = vm_runtime.getDeclaredMethod("registerNativeFree", Integer.TYPE);
792f2472c42be8e80f00019594036744d902e09dcbTim Murray            } catch (Exception e) {
802f2472c42be8e80f00019594036744d902e09dcbTim Murray                Log.e(LOG_TAG, "Error loading GC methods: " + e);
812f2472c42be8e80f00019594036744d902e09dcbTim Murray                throw new RSRuntimeException("Error loading GC methods: " + e);
822f2472c42be8e80f00019594036744d902e09dcbTim Murray            }
832f2472c42be8e80f00019594036744d902e09dcbTim Murray            try {
84e4d9a01bfc7451afff1ed399a5801c7aa2af2831Dan Morrill                System.loadLibrary("rs_jni");
85e4d9a01bfc7451afff1ed399a5801c7aa2af2831Dan Morrill                _nInit();
86e4d9a01bfc7451afff1ed399a5801c7aa2af2831Dan Morrill                sInitialized = true;
87e4d9a01bfc7451afff1ed399a5801c7aa2af2831Dan Morrill            } catch (UnsatisfiedLinkError e) {
88e4d9a01bfc7451afff1ed399a5801c7aa2af2831Dan Morrill                Log.e(LOG_TAG, "Error loading RS jni library: " + e);
89e4d9a01bfc7451afff1ed399a5801c7aa2af2831Dan Morrill                throw new RSRuntimeException("Error loading RS jni library: " + e);
90e4d9a01bfc7451afff1ed399a5801c7aa2af2831Dan Morrill            }
9160aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich        }
9260aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich    }
9360aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
942e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    // Non-threadsafe functions.
9536e612a488511940b61f09803b270aa1c61b68e0Jason Sams    native int  nDeviceCreate();
9636e612a488511940b61f09803b270aa1c61b68e0Jason Sams    native void nDeviceDestroy(int dev);
97ebfb436a49673693b98469683451bd9ede797557Jason Sams    native void nDeviceSetConfig(int dev, int param, int value);
98edbfabdb98a2974f973d6c042e6efd547dc02fc5Jason Sams    native int nContextGetUserMessage(int con, int[] data);
991c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams    native String nContextGetErrorMessage(int con);
100edbfabdb98a2974f973d6c042e6efd547dc02fc5Jason Sams    native int  nContextPeekMessage(int con, int[] subID);
1012e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void nContextInitToClient(int con);
1022e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void nContextDeinitToClient(int con);
1032e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
1047d25a829d3da96fb6ac0d285aa1bfb2022271beeStephen Hines    static File mCacheDir;
105a6f338ca5f0c8359d1952167858851dd025e47e2Jason Sams
106a6f338ca5f0c8359d1952167858851dd025e47e2Jason Sams     /**
107a6f338ca5f0c8359d1952167858851dd025e47e2Jason Sams     * Sets the directory to use as a persistent storage for the
108a6f338ca5f0c8359d1952167858851dd025e47e2Jason Sams     * renderscript object file cache.
109a6f338ca5f0c8359d1952167858851dd025e47e2Jason Sams     *
110a6f338ca5f0c8359d1952167858851dd025e47e2Jason Sams     * @hide
111a6f338ca5f0c8359d1952167858851dd025e47e2Jason Sams     * @param cacheDir A directory the current process can write to
112a6f338ca5f0c8359d1952167858851dd025e47e2Jason Sams     */
113a6f338ca5f0c8359d1952167858851dd025e47e2Jason Sams    public static void setupDiskCache(File cacheDir) {
114e4d9a01bfc7451afff1ed399a5801c7aa2af2831Dan Morrill        if (!sInitialized) {
115e4d9a01bfc7451afff1ed399a5801c7aa2af2831Dan Morrill            Log.e(LOG_TAG, "RenderScript.setupDiskCache() called when disabled");
116e4d9a01bfc7451afff1ed399a5801c7aa2af2831Dan Morrill            return;
117e4d9a01bfc7451afff1ed399a5801c7aa2af2831Dan Morrill        }
118e4d9a01bfc7451afff1ed399a5801c7aa2af2831Dan Morrill
1197d25a829d3da96fb6ac0d285aa1bfb2022271beeStephen Hines        // Defer creation of cache path to nScriptCCreate().
1207d25a829d3da96fb6ac0d285aa1bfb2022271beeStephen Hines        mCacheDir = cacheDir;
121a6f338ca5f0c8359d1952167858851dd025e47e2Jason Sams    }
122a6f338ca5f0c8359d1952167858851dd025e47e2Jason Sams
12302d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams    /**
12402d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams     * ContextType specifies the specific type of context to be created.
12502d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams     *
12602d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams     */
127add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams    public enum ContextType {
12802d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams        /**
12902d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams         * NORMAL context, this is the default and what shipping apps should
13002d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams         * use.
13102d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams         */
132add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams        NORMAL (0),
13302d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams
13402d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams        /**
13502d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams         * DEBUG context, perform extra runtime checks to validate the
13602d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams         * kernels and APIs are being used as intended.  Get and SetElementAt
13702d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams         * will be bounds checked in this mode.
13802d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams         */
139add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams        DEBUG (1),
14002d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams
14102d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams        /**
14202d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams         * PROFILE context, Intended to be used once the first time an
14302d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams         * application is run on a new device.  This mode allows the runtime to
14402d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams         * do additional testing and performance tuning.
14502d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams         */
146add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams        PROFILE (2);
147add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams
148add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams        int mID;
149add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams        ContextType(int id) {
150add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams            mID = id;
151add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams        }
152add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams    }
1532e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
15442028a87568c2b7b5ff3691df7c345bbc5802adeStephen Hines    ContextType mContextType;
155ff7256e757502279b1777127a12eba235be679aeJason Sams    ReentrantReadWriteLock mRWLock;
15642028a87568c2b7b5ff3691df7c345bbc5802adeStephen Hines
1572e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    // Methods below are wrapped to protect the non-threadsafe
1582e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    // lockless fifo.
1594382467a80dd12c6362d57edca7f2367f7ae877cStephen Hines    native int  rsnContextCreateGL(int dev, int ver, int sdkVer,
16011c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams                 int colorMin, int colorPref,
16111c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams                 int alphaMin, int alphaPref,
16211c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams                 int depthMin, int depthPref,
16311c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams                 int stencilMin, int stencilPref,
1642c74ad9aae29cc64fece926f353825a7925792c2Alex Sakhartchouk                 int samplesMin, int samplesPref, float samplesQ, int dpi);
1654382467a80dd12c6362d57edca7f2367f7ae877cStephen Hines    synchronized int nContextCreateGL(int dev, int ver, int sdkVer,
16611c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams                 int colorMin, int colorPref,
16711c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams                 int alphaMin, int alphaPref,
16811c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams                 int depthMin, int depthPref,
16911c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams                 int stencilMin, int stencilPref,
1702c74ad9aae29cc64fece926f353825a7925792c2Alex Sakhartchouk                 int samplesMin, int samplesPref, float samplesQ, int dpi) {
1714382467a80dd12c6362d57edca7f2367f7ae877cStephen Hines        return rsnContextCreateGL(dev, ver, sdkVer, colorMin, colorPref,
17211c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams                                  alphaMin, alphaPref, depthMin, depthPref,
17311c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams                                  stencilMin, stencilPref,
1742c74ad9aae29cc64fece926f353825a7925792c2Alex Sakhartchouk                                  samplesMin, samplesPref, samplesQ, dpi);
1752e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
176add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams    native int  rsnContextCreate(int dev, int ver, int sdkVer, int contextType);
177add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams    synchronized int nContextCreate(int dev, int ver, int sdkVer, int contextType) {
178add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams        return rsnContextCreate(dev, ver, sdkVer, contextType);
1792e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1802e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextDestroy(int con);
1812e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextDestroy() {
182d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
183ff7256e757502279b1777127a12eba235be679aeJason Sams
184ff7256e757502279b1777127a12eba235be679aeJason Sams        // take teardown lock
185ff7256e757502279b1777127a12eba235be679aeJason Sams        // teardown lock can only be taken when no objects are being destroyed
186ff7256e757502279b1777127a12eba235be679aeJason Sams        ReentrantReadWriteLock.WriteLock wlock = mRWLock.writeLock();
187ff7256e757502279b1777127a12eba235be679aeJason Sams        wlock.lock();
188ff7256e757502279b1777127a12eba235be679aeJason Sams
189ff7256e757502279b1777127a12eba235be679aeJason Sams        int curCon = mContext;
190ff7256e757502279b1777127a12eba235be679aeJason Sams        // context is considered dead as of this point
191ff7256e757502279b1777127a12eba235be679aeJason Sams        mContext = 0;
192ff7256e757502279b1777127a12eba235be679aeJason Sams
193ff7256e757502279b1777127a12eba235be679aeJason Sams        wlock.unlock();
194ff7256e757502279b1777127a12eba235be679aeJason Sams        rsnContextDestroy(curCon);
1952e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1962e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextSetSurface(int con, int w, int h, Surface sur);
1972e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextSetSurface(int w, int h, Surface sur) {
198d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
1992e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextSetSurface(mContext, w, h, sur);
2002e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
201faa32b33b50ad941f631716dd0915e936bdc3ac5Jason Sams    native void rsnContextSetSurfaceTexture(int con, int w, int h, SurfaceTexture sur);
202faa32b33b50ad941f631716dd0915e936bdc3ac5Jason Sams    synchronized void nContextSetSurfaceTexture(int w, int h, SurfaceTexture sur) {
203faa32b33b50ad941f631716dd0915e936bdc3ac5Jason Sams        validate();
204faa32b33b50ad941f631716dd0915e936bdc3ac5Jason Sams        rsnContextSetSurfaceTexture(mContext, w, h, sur);
205faa32b33b50ad941f631716dd0915e936bdc3ac5Jason Sams    }
2062e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextSetPriority(int con, int p);
2072e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextSetPriority(int p) {
208d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
2092e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextSetPriority(mContext, p);
2102e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2112e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextDump(int con, int bits);
2122e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextDump(int bits) {
213d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
2142e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextDump(mContext, bits);
2152e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2162e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextFinish(int con);
2172e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextFinish() {
218d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
2192e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextFinish(mContext);
2202e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2212e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
222455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams    native void rsnContextSendMessage(int con, int id, int[] data);
223455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams    synchronized void nContextSendMessage(int id, int[] data) {
224455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams        validate();
225455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams        rsnContextSendMessage(mContext, id, data);
226455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams    }
227455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams
2282e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextBindRootScript(int con, int script);
2292e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextBindRootScript(int script) {
230d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
2312e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextBindRootScript(mContext, script);
2322e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2332e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextBindSampler(int con, int sampler, int slot);
2342e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextBindSampler(int sampler, int slot) {
235d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
2362e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextBindSampler(mContext, sampler, slot);
2372e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2382e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextBindProgramStore(int con, int pfs);
2392e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextBindProgramStore(int pfs) {
240d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
2412e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextBindProgramStore(mContext, pfs);
2422e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2432e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextBindProgramFragment(int con, int pf);
2442e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextBindProgramFragment(int pf) {
245d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
2462e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextBindProgramFragment(mContext, pf);
2472e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2482e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextBindProgramVertex(int con, int pv);
2492e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextBindProgramVertex(int pv) {
250d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
2512e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextBindProgramVertex(mContext, pv);
2522e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2532e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextBindProgramRaster(int con, int pr);
2542e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextBindProgramRaster(int pr) {
255d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
2562e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextBindProgramRaster(mContext, pr);
2572e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2582e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextPause(int con);
2592e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextPause() {
260d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
2612e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextPause(mContext);
2622e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2632e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextResume(int con);
2642e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextResume() {
265d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
2662e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextResume(mContext);
2672e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2682e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
2692e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAssignName(int con, int obj, byte[] name);
2702e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAssignName(int obj, byte[] name) {
271d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
2722e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAssignName(mContext, obj, name);
2732e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2742e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native String rsnGetName(int con, int obj);
2752e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized String nGetName(int obj) {
276d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
2772e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnGetName(mContext, obj);
2782e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
279ff7256e757502279b1777127a12eba235be679aeJason Sams    // nObjDestroy is explicitly _not_ synchronous to prevent crashes in finalizers
2802e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnObjDestroy(int con, int id);
281ff7256e757502279b1777127a12eba235be679aeJason Sams    void nObjDestroy(int id) {
282d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        // There is a race condition here.  The calling code may be run
283d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        // by the gc while teardown is occuring.  This protects againts
284d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        // deleting dead objects.
285d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        if (mContext != 0) {
286d1ac98149737299513da1357e36f68cbb6d74425Jason Sams            rsnObjDestroy(mContext, id);
287d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        }
2882e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2892e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
2902e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnElementCreate(int con, int type, int kind, boolean norm, int vecSize);
2912e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nElementCreate(int type, int kind, boolean norm, int vecSize) {
292d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
2932e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnElementCreate(mContext, type, kind, norm, vecSize);
2942e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
29570d4e5024298f71edb3b04867e05568f5495b4ceJason Sams    native int  rsnElementCreate2(int con, int[] elements, String[] names, int[] arraySizes);
29670d4e5024298f71edb3b04867e05568f5495b4ceJason Sams    synchronized int nElementCreate2(int[] elements, String[] names, int[] arraySizes) {
297d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
29870d4e5024298f71edb3b04867e05568f5495b4ceJason Sams        return rsnElementCreate2(mContext, elements, names, arraySizes);
2992e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3002e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnElementGetNativeData(int con, int id, int[] elementData);
3012e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nElementGetNativeData(int id, int[] elementData) {
302d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
3032e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnElementGetNativeData(mContext, id, elementData);
3042e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3057d5f5e7c8943e043a422ad51c85d4e1684c37e28Alex Sakhartchouk    native void rsnElementGetSubElements(int con, int id,
3067d5f5e7c8943e043a422ad51c85d4e1684c37e28Alex Sakhartchouk                                         int[] IDs, String[] names, int[] arraySizes);
3077d5f5e7c8943e043a422ad51c85d4e1684c37e28Alex Sakhartchouk    synchronized void nElementGetSubElements(int id, int[] IDs, String[] names, int[] arraySizes) {
308d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
3097d5f5e7c8943e043a422ad51c85d4e1684c37e28Alex Sakhartchouk        rsnElementGetSubElements(mContext, id, IDs, names, arraySizes);
3102e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3112e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
312b109cc78616abee7291eb42094cd156b5db3355dJason Sams    native int rsnTypeCreate(int con, int eid, int x, int y, int z, boolean mips, boolean faces, int yuv);
313b109cc78616abee7291eb42094cd156b5db3355dJason Sams    synchronized int nTypeCreate(int eid, int x, int y, int z, boolean mips, boolean faces, int yuv) {
314d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
315b109cc78616abee7291eb42094cd156b5db3355dJason Sams        return rsnTypeCreate(mContext, eid, x, y, z, mips, faces, yuv);
3162e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3172e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnTypeGetNativeData(int con, int id, int[] typeData);
3182e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nTypeGetNativeData(int id, int[] typeData) {
319d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
3202e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnTypeGetNativeData(mContext, id, typeData);
3212e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3222e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
323857d0c7017da763a420e825fffa2f260eb982c97Jason Sams    native int  rsnAllocationCreateTyped(int con, int type, int mip, int usage, int pointer);
324857d0c7017da763a420e825fffa2f260eb982c97Jason Sams    synchronized int nAllocationCreateTyped(int type, int mip, int usage, int pointer) {
325d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
326857d0c7017da763a420e825fffa2f260eb982c97Jason Sams        return rsnAllocationCreateTyped(mContext, type, mip, usage, pointer);
3272e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3285476b450e50939940dcf3f15c92335cee2fc572dJason Sams    native int  rsnAllocationCreateFromBitmap(int con, int type, int mip, Bitmap bmp, int usage);
3295476b450e50939940dcf3f15c92335cee2fc572dJason Sams    synchronized int nAllocationCreateFromBitmap(int type, int mip, Bitmap bmp, int usage) {
330d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
3315476b450e50939940dcf3f15c92335cee2fc572dJason Sams        return rsnAllocationCreateFromBitmap(mContext, type, mip, bmp, usage);
33226ae3904e8050eae655722caf93ee5d3f0ab195aAlex Sakhartchouk    }
333a314551d69098537337c970da615a8f8af58e1f1Tim Murray
334a314551d69098537337c970da615a8f8af58e1f1Tim Murray    native int  rsnAllocationCreateBitmapBackedAllocation(int con, int type, int mip, Bitmap bmp, int usage);
335a314551d69098537337c970da615a8f8af58e1f1Tim Murray    synchronized int nAllocationCreateBitmapBackedAllocation(int type, int mip, Bitmap bmp, int usage) {
336a314551d69098537337c970da615a8f8af58e1f1Tim Murray        validate();
337a314551d69098537337c970da615a8f8af58e1f1Tim Murray        return rsnAllocationCreateBitmapBackedAllocation(mContext, type, mip, bmp, usage);
338a314551d69098537337c970da615a8f8af58e1f1Tim Murray    }
339a314551d69098537337c970da615a8f8af58e1f1Tim Murray
340a314551d69098537337c970da615a8f8af58e1f1Tim Murray
3415476b450e50939940dcf3f15c92335cee2fc572dJason Sams    native int  rsnAllocationCubeCreateFromBitmap(int con, int type, int mip, Bitmap bmp, int usage);
3425476b450e50939940dcf3f15c92335cee2fc572dJason Sams    synchronized int nAllocationCubeCreateFromBitmap(int type, int mip, Bitmap bmp, int usage) {
343d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
3445476b450e50939940dcf3f15c92335cee2fc572dJason Sams        return rsnAllocationCubeCreateFromBitmap(mContext, type, mip, bmp, usage);
34567f2e442a31b8395e3c1951f8e91139ec7f2be99Alex Sakhartchouk    }
3462e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnAllocationCreateBitmapRef(int con, int type, Bitmap bmp);
3472e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nAllocationCreateBitmapRef(int type, Bitmap bmp) {
348d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
3492e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnAllocationCreateBitmapRef(mContext, type, bmp);
3502e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3515476b450e50939940dcf3f15c92335cee2fc572dJason Sams    native int  rsnAllocationCreateFromAssetStream(int con, int mips, int assetStream, int usage);
3525476b450e50939940dcf3f15c92335cee2fc572dJason Sams    synchronized int nAllocationCreateFromAssetStream(int mips, int assetStream, int usage) {
353d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
3545476b450e50939940dcf3f15c92335cee2fc572dJason Sams        return rsnAllocationCreateFromAssetStream(mContext, mips, assetStream, usage);
3555476b450e50939940dcf3f15c92335cee2fc572dJason Sams    }
3565476b450e50939940dcf3f15c92335cee2fc572dJason Sams
3574ef6650bd05a39a09958ea1db92f120ea4949cb1Jason Sams    native void  rsnAllocationCopyToBitmap(int con, int alloc, Bitmap bmp);
3584ef6650bd05a39a09958ea1db92f120ea4949cb1Jason Sams    synchronized void nAllocationCopyToBitmap(int alloc, Bitmap bmp) {
359d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
3604ef6650bd05a39a09958ea1db92f120ea4949cb1Jason Sams        rsnAllocationCopyToBitmap(mContext, alloc, bmp);
3614ef6650bd05a39a09958ea1db92f120ea4949cb1Jason Sams    }
3624ef6650bd05a39a09958ea1db92f120ea4949cb1Jason Sams
3634ef6650bd05a39a09958ea1db92f120ea4949cb1Jason Sams
3645476b450e50939940dcf3f15c92335cee2fc572dJason Sams    native void rsnAllocationSyncAll(int con, int alloc, int src);
3655476b450e50939940dcf3f15c92335cee2fc572dJason Sams    synchronized void nAllocationSyncAll(int alloc, int src) {
366d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
3675476b450e50939940dcf3f15c92335cee2fc572dJason Sams        rsnAllocationSyncAll(mContext, alloc, src);
3685476b450e50939940dcf3f15c92335cee2fc572dJason Sams    }
36972226e0543461133b9e177a3e78ae50b0c65e797Jason Sams    native Surface rsnAllocationGetSurface(int con, int alloc);
37072226e0543461133b9e177a3e78ae50b0c65e797Jason Sams    synchronized Surface nAllocationGetSurface(int alloc) {
371615e7cee03d1a53072b0369fa9f247811ac56845Jason Sams        validate();
37272226e0543461133b9e177a3e78ae50b0c65e797Jason Sams        return rsnAllocationGetSurface(mContext, alloc);
373fe1d5ffd1b6c4977a9f301997d2ad90e5b049a3bJason Sams    }
374fb9aa9f3ef11878caaf6fcfb5ea49ffb9f7abf33Jason Sams    native void rsnAllocationSetSurface(int con, int alloc, Surface sur);
375fb9aa9f3ef11878caaf6fcfb5ea49ffb9f7abf33Jason Sams    synchronized void nAllocationSetSurface(int alloc, Surface sur) {
376163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams        validate();
377fb9aa9f3ef11878caaf6fcfb5ea49ffb9f7abf33Jason Sams        rsnAllocationSetSurface(mContext, alloc, sur);
378163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams    }
379163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams    native void rsnAllocationIoSend(int con, int alloc);
380163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams    synchronized void nAllocationIoSend(int alloc) {
381163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams        validate();
382163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams        rsnAllocationIoSend(mContext, alloc);
383163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams    }
384163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams    native void rsnAllocationIoReceive(int con, int alloc);
385163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams    synchronized void nAllocationIoReceive(int alloc) {
386163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams        validate();
387163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams        rsnAllocationIoReceive(mContext, alloc);
388163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams    }
389163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams
390615e7cee03d1a53072b0369fa9f247811ac56845Jason Sams
391f7086090cfc8d97b5bd3b4d7801a27af11f7c207Jason Sams    native void rsnAllocationGenerateMipmaps(int con, int alloc);
392f7086090cfc8d97b5bd3b4d7801a27af11f7c207Jason Sams    synchronized void nAllocationGenerateMipmaps(int alloc) {
393d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
394f7086090cfc8d97b5bd3b4d7801a27af11f7c207Jason Sams        rsnAllocationGenerateMipmaps(mContext, alloc);
395f7086090cfc8d97b5bd3b4d7801a27af11f7c207Jason Sams    }
3964ef6650bd05a39a09958ea1db92f120ea4949cb1Jason Sams    native void  rsnAllocationCopyFromBitmap(int con, int alloc, Bitmap bmp);
3974ef6650bd05a39a09958ea1db92f120ea4949cb1Jason Sams    synchronized void nAllocationCopyFromBitmap(int alloc, Bitmap bmp) {
398d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
3994ef6650bd05a39a09958ea1db92f120ea4949cb1Jason Sams        rsnAllocationCopyFromBitmap(mContext, alloc, bmp);
4002e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4012e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
4022e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
40349a05d7b82956009f03acbb92a064eed054eb031Jason Sams    native void rsnAllocationData1D(int con, int id, int off, int mip, int count, int[] d, int sizeBytes);
40449a05d7b82956009f03acbb92a064eed054eb031Jason Sams    synchronized void nAllocationData1D(int id, int off, int mip, int count, int[] d, int sizeBytes) {
405d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
40649a05d7b82956009f03acbb92a064eed054eb031Jason Sams        rsnAllocationData1D(mContext, id, off, mip, count, d, sizeBytes);
4072e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
40849a05d7b82956009f03acbb92a064eed054eb031Jason Sams    native void rsnAllocationData1D(int con, int id, int off, int mip, int count, short[] d, int sizeBytes);
40949a05d7b82956009f03acbb92a064eed054eb031Jason Sams    synchronized void nAllocationData1D(int id, int off, int mip, int count, short[] d, int sizeBytes) {
410d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
41149a05d7b82956009f03acbb92a064eed054eb031Jason Sams        rsnAllocationData1D(mContext, id, off, mip, count, d, sizeBytes);
4122e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
41349a05d7b82956009f03acbb92a064eed054eb031Jason Sams    native void rsnAllocationData1D(int con, int id, int off, int mip, int count, byte[] d, int sizeBytes);
41449a05d7b82956009f03acbb92a064eed054eb031Jason Sams    synchronized void nAllocationData1D(int id, int off, int mip, int count, byte[] d, int sizeBytes) {
415d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
41649a05d7b82956009f03acbb92a064eed054eb031Jason Sams        rsnAllocationData1D(mContext, id, off, mip, count, d, sizeBytes);
4172e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
41849a05d7b82956009f03acbb92a064eed054eb031Jason Sams    native void rsnAllocationData1D(int con, int id, int off, int mip, int count, float[] d, int sizeBytes);
41949a05d7b82956009f03acbb92a064eed054eb031Jason Sams    synchronized void nAllocationData1D(int id, int off, int mip, int count, float[] d, int sizeBytes) {
420d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
42149a05d7b82956009f03acbb92a064eed054eb031Jason Sams        rsnAllocationData1D(mContext, id, off, mip, count, d, sizeBytes);
42249bdaf0293408159df18a1d8540360f9623c40f7Jason Sams    }
42349a05d7b82956009f03acbb92a064eed054eb031Jason Sams
42449a05d7b82956009f03acbb92a064eed054eb031Jason Sams    native void rsnAllocationElementData1D(int con, int id, int xoff, int mip, int compIdx, byte[] d, int sizeBytes);
42549a05d7b82956009f03acbb92a064eed054eb031Jason Sams    synchronized void nAllocationElementData1D(int id, int xoff, int mip, int compIdx, byte[] d, int sizeBytes) {
426d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
42749a05d7b82956009f03acbb92a064eed054eb031Jason Sams        rsnAllocationElementData1D(mContext, id, xoff, mip, compIdx, d, sizeBytes);
4282e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4292e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
430304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk    native void rsnAllocationData2D(int con,
431304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                                    int dstAlloc, int dstXoff, int dstYoff,
432304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                                    int dstMip, int dstFace,
433304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                                    int width, int height,
434304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                                    int srcAlloc, int srcXoff, int srcYoff,
435304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                                    int srcMip, int srcFace);
436304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk    synchronized void nAllocationData2D(int dstAlloc, int dstXoff, int dstYoff,
437304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                                        int dstMip, int dstFace,
438304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                                        int width, int height,
439304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                                        int srcAlloc, int srcXoff, int srcYoff,
440304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                                        int srcMip, int srcFace) {
441304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk        validate();
442304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk        rsnAllocationData2D(mContext,
443304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                            dstAlloc, dstXoff, dstYoff,
444304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                            dstMip, dstFace,
445304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                            width, height,
446304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                            srcAlloc, srcXoff, srcYoff,
447304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                            srcMip, srcFace);
448304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk    }
449304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk
450fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    native void rsnAllocationData2D(int con, int id, int xoff, int yoff, int mip, int face, int w, int h, byte[] d, int sizeBytes);
451fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    synchronized void nAllocationData2D(int id, int xoff, int yoff, int mip, int face, int w, int h, byte[] d, int sizeBytes) {
452d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
453fa445b9353972735d8d65e8a936786b1afe9886dJason Sams        rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes);
454fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    }
455fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    native void rsnAllocationData2D(int con, int id, int xoff, int yoff, int mip, int face, int w, int h, short[] d, int sizeBytes);
456fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    synchronized void nAllocationData2D(int id, int xoff, int yoff, int mip, int face, int w, int h, short[] d, int sizeBytes) {
457d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
458fa445b9353972735d8d65e8a936786b1afe9886dJason Sams        rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes);
459fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    }
46049a05d7b82956009f03acbb92a064eed054eb031Jason Sams    native void rsnAllocationData2D(int con, int id, int xoff, int yoff, int mip, int face, int w, int h, int[] d, int sizeBytes);
46149a05d7b82956009f03acbb92a064eed054eb031Jason Sams    synchronized void nAllocationData2D(int id, int xoff, int yoff, int mip, int face, int w, int h, int[] d, int sizeBytes) {
462d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
46349a05d7b82956009f03acbb92a064eed054eb031Jason Sams        rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes);
4642e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
46549a05d7b82956009f03acbb92a064eed054eb031Jason Sams    native void rsnAllocationData2D(int con, int id, int xoff, int yoff, int mip, int face, int w, int h, float[] d, int sizeBytes);
46649a05d7b82956009f03acbb92a064eed054eb031Jason Sams    synchronized void nAllocationData2D(int id, int xoff, int yoff, int mip, int face, int w, int h, float[] d, int sizeBytes) {
467d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
46849a05d7b82956009f03acbb92a064eed054eb031Jason Sams        rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes);
4692e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
470fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    native void rsnAllocationData2D(int con, int id, int xoff, int yoff, int mip, int face, Bitmap b);
471fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    synchronized void nAllocationData2D(int id, int xoff, int yoff, int mip, int face, Bitmap b) {
472d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
473fa445b9353972735d8d65e8a936786b1afe9886dJason Sams        rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, b);
474fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    }
47549a05d7b82956009f03acbb92a064eed054eb031Jason Sams
476b05d689653b1bc94836f716f29e9578677c29075Jason Sams    native void rsnAllocationData3D(int con,
477b05d689653b1bc94836f716f29e9578677c29075Jason Sams                                    int dstAlloc, int dstXoff, int dstYoff, int dstZoff,
478b05d689653b1bc94836f716f29e9578677c29075Jason Sams                                    int dstMip,
479b05d689653b1bc94836f716f29e9578677c29075Jason Sams                                    int width, int height, int depth,
480b05d689653b1bc94836f716f29e9578677c29075Jason Sams                                    int srcAlloc, int srcXoff, int srcYoff, int srcZoff,
481b05d689653b1bc94836f716f29e9578677c29075Jason Sams                                    int srcMip);
482b05d689653b1bc94836f716f29e9578677c29075Jason Sams    synchronized void nAllocationData3D(int dstAlloc, int dstXoff, int dstYoff, int dstZoff,
483b05d689653b1bc94836f716f29e9578677c29075Jason Sams                                        int dstMip,
484b05d689653b1bc94836f716f29e9578677c29075Jason Sams                                        int width, int height, int depth,
485b05d689653b1bc94836f716f29e9578677c29075Jason Sams                                        int srcAlloc, int srcXoff, int srcYoff, int srcZoff,
486b05d689653b1bc94836f716f29e9578677c29075Jason Sams                                        int srcMip) {
487b05d689653b1bc94836f716f29e9578677c29075Jason Sams        validate();
488b05d689653b1bc94836f716f29e9578677c29075Jason Sams        rsnAllocationData3D(mContext,
489b05d689653b1bc94836f716f29e9578677c29075Jason Sams                            dstAlloc, dstXoff, dstYoff, dstZoff,
490b05d689653b1bc94836f716f29e9578677c29075Jason Sams                            dstMip, width, height, depth,
491b05d689653b1bc94836f716f29e9578677c29075Jason Sams                            srcAlloc, srcXoff, srcYoff, srcZoff, srcMip);
492b05d689653b1bc94836f716f29e9578677c29075Jason Sams    }
493b05d689653b1bc94836f716f29e9578677c29075Jason Sams
494b05d689653b1bc94836f716f29e9578677c29075Jason Sams    native void rsnAllocationData3D(int con, int id, int xoff, int yoff, int zoff, int mip, int w, int h, int depth, byte[] d, int sizeBytes);
495b05d689653b1bc94836f716f29e9578677c29075Jason Sams    synchronized void nAllocationData3D(int id, int xoff, int yoff, int zoff, int mip, int w, int h, int depth, byte[] d, int sizeBytes) {
496b05d689653b1bc94836f716f29e9578677c29075Jason Sams        validate();
497b05d689653b1bc94836f716f29e9578677c29075Jason Sams        rsnAllocationData3D(mContext, id, xoff, yoff, zoff, mip, w, h, depth, d, sizeBytes);
498b05d689653b1bc94836f716f29e9578677c29075Jason Sams    }
499b05d689653b1bc94836f716f29e9578677c29075Jason Sams    native void rsnAllocationData3D(int con, int id, int xoff, int yoff, int zoff, int mip, int w, int h, int depth, short[] d, int sizeBytes);
500b05d689653b1bc94836f716f29e9578677c29075Jason Sams    synchronized void nAllocationData3D(int id, int xoff, int yoff, int zoff, int mip, int w, int h, int depth, short[] d, int sizeBytes) {
501b05d689653b1bc94836f716f29e9578677c29075Jason Sams        validate();
502b05d689653b1bc94836f716f29e9578677c29075Jason Sams        rsnAllocationData3D(mContext, id, xoff, yoff, zoff, mip, w, h, depth, d, sizeBytes);
503b05d689653b1bc94836f716f29e9578677c29075Jason Sams    }
504b05d689653b1bc94836f716f29e9578677c29075Jason Sams    native void rsnAllocationData3D(int con, int id, int xoff, int yoff, int zoff, int mip, int w, int h, int depth, int[] d, int sizeBytes);
505b05d689653b1bc94836f716f29e9578677c29075Jason Sams    synchronized void nAllocationData3D(int id, int xoff, int yoff, int zoff, int mip, int w, int h, int depth, int[] d, int sizeBytes) {
506b05d689653b1bc94836f716f29e9578677c29075Jason Sams        validate();
507b05d689653b1bc94836f716f29e9578677c29075Jason Sams        rsnAllocationData3D(mContext, id, xoff, yoff, zoff, mip, w, h, depth, d, sizeBytes);
508b05d689653b1bc94836f716f29e9578677c29075Jason Sams    }
509b05d689653b1bc94836f716f29e9578677c29075Jason Sams    native void rsnAllocationData3D(int con, int id, int xoff, int yoff, int zoff, int mip, int w, int h, int depth, float[] d, int sizeBytes);
510b05d689653b1bc94836f716f29e9578677c29075Jason Sams    synchronized void nAllocationData3D(int id, int xoff, int yoff, int zoff, int mip, int w, int h, int depth, float[] d, int sizeBytes) {
511b05d689653b1bc94836f716f29e9578677c29075Jason Sams        validate();
512b05d689653b1bc94836f716f29e9578677c29075Jason Sams        rsnAllocationData3D(mContext, id, xoff, yoff, zoff, mip, w, h, depth, d, sizeBytes);
513b05d689653b1bc94836f716f29e9578677c29075Jason Sams    }
514b05d689653b1bc94836f716f29e9578677c29075Jason Sams
515b05d689653b1bc94836f716f29e9578677c29075Jason Sams
516fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    native void rsnAllocationRead(int con, int id, byte[] d);
517fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    synchronized void nAllocationRead(int id, byte[] d) {
518d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
519fa445b9353972735d8d65e8a936786b1afe9886dJason Sams        rsnAllocationRead(mContext, id, d);
520fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    }
521fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    native void rsnAllocationRead(int con, int id, short[] d);
522fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    synchronized void nAllocationRead(int id, short[] d) {
523d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
524fa445b9353972735d8d65e8a936786b1afe9886dJason Sams        rsnAllocationRead(mContext, id, d);
525fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    }
5262e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAllocationRead(int con, int id, int[] d);
5272e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAllocationRead(int id, int[] d) {
528d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
5292e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAllocationRead(mContext, id, d);
5302e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
5312e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAllocationRead(int con, int id, float[] d);
5322e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAllocationRead(int id, float[] d) {
533d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
5342e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAllocationRead(mContext, id, d);
5352e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
5362e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnAllocationGetType(int con, int id);
5372e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nAllocationGetType(int id) {
538d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
5392e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnAllocationGetType(mContext, id);
5402e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
5412e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
5425edc608a0749ed4b7074b5c1243043eb722c3c31Jason Sams    native void rsnAllocationResize1D(int con, int id, int dimX);
5435edc608a0749ed4b7074b5c1243043eb722c3c31Jason Sams    synchronized void nAllocationResize1D(int id, int dimX) {
544d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
5455edc608a0749ed4b7074b5c1243043eb722c3c31Jason Sams        rsnAllocationResize1D(mContext, id, dimX);
5465edc608a0749ed4b7074b5c1243043eb722c3c31Jason Sams    }
5475edc608a0749ed4b7074b5c1243043eb722c3c31Jason Sams
5482e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnFileA3DCreateFromAssetStream(int con, int assetStream);
5492e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nFileA3DCreateFromAssetStream(int assetStream) {
550d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
5512e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnFileA3DCreateFromAssetStream(mContext, assetStream);
5522e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
553b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    native int  rsnFileA3DCreateFromFile(int con, String path);
554b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    synchronized int nFileA3DCreateFromFile(String path) {
555d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
556b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk        return rsnFileA3DCreateFromFile(mContext, path);
557b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    }
558b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    native int  rsnFileA3DCreateFromAsset(int con, AssetManager mgr, String path);
559b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    synchronized int nFileA3DCreateFromAsset(AssetManager mgr, String path) {
560d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
561b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk        return rsnFileA3DCreateFromAsset(mContext, mgr, path);
562b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    }
5632e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnFileA3DGetNumIndexEntries(int con, int fileA3D);
5642e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nFileA3DGetNumIndexEntries(int fileA3D) {
565d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
5662e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnFileA3DGetNumIndexEntries(mContext, fileA3D);
5672e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
5682e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnFileA3DGetIndexEntries(int con, int fileA3D, int numEntries, int[] IDs, String[] names);
5692e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nFileA3DGetIndexEntries(int fileA3D, int numEntries, int[] IDs, String[] names) {
570d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
5712e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnFileA3DGetIndexEntries(mContext, fileA3D, numEntries, IDs, names);
5722e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
5732e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnFileA3DGetEntryByIndex(int con, int fileA3D, int index);
5742e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nFileA3DGetEntryByIndex(int fileA3D, int index) {
575d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
5762e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnFileA3DGetEntryByIndex(mContext, fileA3D, index);
5772e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
5782e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
579e27cdeeecba5b445e307d653d9cb7da007adfac3Alex Sakhartchouk    native int  rsnFontCreateFromFile(int con, String fileName, float size, int dpi);
580e27cdeeecba5b445e307d653d9cb7da007adfac3Alex Sakhartchouk    synchronized int nFontCreateFromFile(String fileName, float size, int dpi) {
581d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
5822e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnFontCreateFromFile(mContext, fileName, size, dpi);
5832e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
584b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    native int  rsnFontCreateFromAssetStream(int con, String name, float size, int dpi, int assetStream);
585b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    synchronized int nFontCreateFromAssetStream(String name, float size, int dpi, int assetStream) {
586d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
587b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk        return rsnFontCreateFromAssetStream(mContext, name, size, dpi, assetStream);
588b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    }
589b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    native int  rsnFontCreateFromAsset(int con, AssetManager mgr, String path, float size, int dpi);
590b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    synchronized int nFontCreateFromAsset(AssetManager mgr, String path, float size, int dpi) {
591d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
592b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk        return rsnFontCreateFromAsset(mContext, mgr, path, size, dpi);
593b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    }
5942e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
5952e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
5962e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnScriptBindAllocation(int con, int script, int alloc, int slot);
5972e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nScriptBindAllocation(int script, int alloc, int slot) {
598d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
5992e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnScriptBindAllocation(mContext, script, alloc, slot);
6002e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
6012e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnScriptSetTimeZone(int con, int script, byte[] timeZone);
6022e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nScriptSetTimeZone(int script, byte[] timeZone) {
603d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
6042e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnScriptSetTimeZone(mContext, script, timeZone);
6052e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
6062e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnScriptInvoke(int con, int id, int slot);
6072e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nScriptInvoke(int id, int slot) {
608d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
6092e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnScriptInvoke(mContext, id, slot);
6102e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
6116e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams    native void rsnScriptForEach(int con, int id, int slot, int ain, int aout, byte[] params);
6126e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams    native void rsnScriptForEach(int con, int id, int slot, int ain, int aout);
613eb8c29cb7ece3f4b7ad18e5393b07fa7418a541cTim Murray    native void rsnScriptForEachClipped(int con, int id, int slot, int ain, int aout, byte[] params,
614eb8c29cb7ece3f4b7ad18e5393b07fa7418a541cTim Murray                                        int xstart, int xend, int ystart, int yend, int zstart, int zend);
615dac6ed0b69b23ab25757085dd5ce68092516ee2fStephen Hines    native void rsnScriptForEachClipped(int con, int id, int slot, int ain, int aout,
616dac6ed0b69b23ab25757085dd5ce68092516ee2fStephen Hines                                        int xstart, int xend, int ystart, int yend, int zstart, int zend);
6176e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams    synchronized void nScriptForEach(int id, int slot, int ain, int aout, byte[] params) {
6186e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams        validate();
6196e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams        if (params == null) {
6206e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams            rsnScriptForEach(mContext, id, slot, ain, aout);
6216e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams        } else {
6226e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams            rsnScriptForEach(mContext, id, slot, ain, aout, params);
6236e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams        }
6246e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams    }
625eb8c29cb7ece3f4b7ad18e5393b07fa7418a541cTim Murray
626eb8c29cb7ece3f4b7ad18e5393b07fa7418a541cTim Murray    synchronized void nScriptForEachClipped(int id, int slot, int ain, int aout, byte[] params,
627eb8c29cb7ece3f4b7ad18e5393b07fa7418a541cTim Murray                                            int xstart, int xend, int ystart, int yend, int zstart, int zend) {
628eb8c29cb7ece3f4b7ad18e5393b07fa7418a541cTim Murray        validate();
629dac6ed0b69b23ab25757085dd5ce68092516ee2fStephen Hines        if (params == null) {
630dac6ed0b69b23ab25757085dd5ce68092516ee2fStephen Hines            rsnScriptForEachClipped(mContext, id, slot, ain, aout, xstart, xend, ystart, yend, zstart, zend);
631dac6ed0b69b23ab25757085dd5ce68092516ee2fStephen Hines        } else {
632dac6ed0b69b23ab25757085dd5ce68092516ee2fStephen Hines            rsnScriptForEachClipped(mContext, id, slot, ain, aout, params, xstart, xend, ystart, yend, zstart, zend);
633dac6ed0b69b23ab25757085dd5ce68092516ee2fStephen Hines        }
634eb8c29cb7ece3f4b7ad18e5393b07fa7418a541cTim Murray    }
635eb8c29cb7ece3f4b7ad18e5393b07fa7418a541cTim Murray
6362e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnScriptInvokeV(int con, int id, int slot, byte[] params);
6372e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nScriptInvokeV(int id, int slot, byte[] params) {
638d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
6392e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnScriptInvokeV(mContext, id, slot, params);
6402e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
6417c4caadb939b1563328251c156262c179a685c70Tim Murray
6422e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnScriptSetVarI(int con, int id, int slot, int val);
6432e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nScriptSetVarI(int id, int slot, int val) {
644d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
6452e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnScriptSetVarI(mContext, id, slot, val);
6462e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
6477c4caadb939b1563328251c156262c179a685c70Tim Murray    native int rsnScriptGetVarI(int con, int id, int slot);
6487c4caadb939b1563328251c156262c179a685c70Tim Murray    synchronized int nScriptGetVarI(int id, int slot) {
6497c4caadb939b1563328251c156262c179a685c70Tim Murray        validate();
6507c4caadb939b1563328251c156262c179a685c70Tim Murray        return rsnScriptGetVarI(mContext, id, slot);
6517c4caadb939b1563328251c156262c179a685c70Tim Murray    }
6527c4caadb939b1563328251c156262c179a685c70Tim Murray
653031ec58cfc7a20927302a5300eba3f5fc1709b50Stephen Hines    native void rsnScriptSetVarJ(int con, int id, int slot, long val);
654031ec58cfc7a20927302a5300eba3f5fc1709b50Stephen Hines    synchronized void nScriptSetVarJ(int id, int slot, long val) {
655d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
656031ec58cfc7a20927302a5300eba3f5fc1709b50Stephen Hines        rsnScriptSetVarJ(mContext, id, slot, val);
657031ec58cfc7a20927302a5300eba3f5fc1709b50Stephen Hines    }
6587c4caadb939b1563328251c156262c179a685c70Tim Murray    native long rsnScriptGetVarJ(int con, int id, int slot);
6597c4caadb939b1563328251c156262c179a685c70Tim Murray    synchronized long nScriptGetVarJ(int id, int slot) {
6607c4caadb939b1563328251c156262c179a685c70Tim Murray        validate();
6617c4caadb939b1563328251c156262c179a685c70Tim Murray        return rsnScriptGetVarJ(mContext, id, slot);
6627c4caadb939b1563328251c156262c179a685c70Tim Murray    }
6637c4caadb939b1563328251c156262c179a685c70Tim Murray
6642e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnScriptSetVarF(int con, int id, int slot, float val);
6652e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nScriptSetVarF(int id, int slot, float val) {
666d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
6672e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnScriptSetVarF(mContext, id, slot, val);
6682e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
6697c4caadb939b1563328251c156262c179a685c70Tim Murray    native float rsnScriptGetVarF(int con, int id, int slot);
6707c4caadb939b1563328251c156262c179a685c70Tim Murray    synchronized float nScriptGetVarF(int id, int slot) {
6717c4caadb939b1563328251c156262c179a685c70Tim Murray        validate();
6727c4caadb939b1563328251c156262c179a685c70Tim Murray        return rsnScriptGetVarF(mContext, id, slot);
6737c4caadb939b1563328251c156262c179a685c70Tim Murray    }
674ca54ec302f5bddd1674ea1f36cd3b7c540b2fbcaStephen Hines    native void rsnScriptSetVarD(int con, int id, int slot, double val);
675ca54ec302f5bddd1674ea1f36cd3b7c540b2fbcaStephen Hines    synchronized void nScriptSetVarD(int id, int slot, double val) {
676d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
677ca54ec302f5bddd1674ea1f36cd3b7c540b2fbcaStephen Hines        rsnScriptSetVarD(mContext, id, slot, val);
678ca54ec302f5bddd1674ea1f36cd3b7c540b2fbcaStephen Hines    }
6797c4caadb939b1563328251c156262c179a685c70Tim Murray    native double rsnScriptGetVarD(int con, int id, int slot);
6807c4caadb939b1563328251c156262c179a685c70Tim Murray    synchronized double nScriptGetVarD(int id, int slot) {
6817c4caadb939b1563328251c156262c179a685c70Tim Murray        validate();
6827c4caadb939b1563328251c156262c179a685c70Tim Murray        return rsnScriptGetVarD(mContext, id, slot);
6837c4caadb939b1563328251c156262c179a685c70Tim Murray    }
6842e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnScriptSetVarV(int con, int id, int slot, byte[] val);
6852e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nScriptSetVarV(int id, int slot, byte[] val) {
686d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
6872e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnScriptSetVarV(mContext, id, slot, val);
6882e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
6897c4caadb939b1563328251c156262c179a685c70Tim Murray    native void rsnScriptGetVarV(int con, int id, int slot, byte[] val);
6907c4caadb939b1563328251c156262c179a685c70Tim Murray    synchronized void nScriptGetVarV(int id, int slot, byte[] val) {
6917c4caadb939b1563328251c156262c179a685c70Tim Murray        validate();
6927c4caadb939b1563328251c156262c179a685c70Tim Murray        rsnScriptGetVarV(mContext, id, slot, val);
6937c4caadb939b1563328251c156262c179a685c70Tim Murray    }
694adeb809201fcb77ba2b76a814ae4cdc9dacb326bStephen Hines    native void rsnScriptSetVarVE(int con, int id, int slot, byte[] val,
695adeb809201fcb77ba2b76a814ae4cdc9dacb326bStephen Hines                                  int e, int[] dims);
696adeb809201fcb77ba2b76a814ae4cdc9dacb326bStephen Hines    synchronized void nScriptSetVarVE(int id, int slot, byte[] val,
697adeb809201fcb77ba2b76a814ae4cdc9dacb326bStephen Hines                                      int e, int[] dims) {
698adeb809201fcb77ba2b76a814ae4cdc9dacb326bStephen Hines        validate();
699adeb809201fcb77ba2b76a814ae4cdc9dacb326bStephen Hines        rsnScriptSetVarVE(mContext, id, slot, val, e, dims);
700adeb809201fcb77ba2b76a814ae4cdc9dacb326bStephen Hines    }
7016f4cf0b8885403ead157ae00fd43cf1282331c23Jason Sams    native void rsnScriptSetVarObj(int con, int id, int slot, int val);
7026f4cf0b8885403ead157ae00fd43cf1282331c23Jason Sams    synchronized void nScriptSetVarObj(int id, int slot, int val) {
703d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
7046f4cf0b8885403ead157ae00fd43cf1282331c23Jason Sams        rsnScriptSetVarObj(mContext, id, slot, val);
7056f4cf0b8885403ead157ae00fd43cf1282331c23Jason Sams    }
7062e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
707e4a06c5fc738bf219f2a495e12a637b2d0871651Jason Sams    native int  rsnScriptCCreate(int con, String resName, String cacheDir,
708e4a06c5fc738bf219f2a495e12a637b2d0871651Jason Sams                                 byte[] script, int length);
709e4a06c5fc738bf219f2a495e12a637b2d0871651Jason Sams    synchronized int nScriptCCreate(String resName, String cacheDir, byte[] script, int length) {
710d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
711e4a06c5fc738bf219f2a495e12a637b2d0871651Jason Sams        return rsnScriptCCreate(mContext, resName, cacheDir, script, length);
7122e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
7132e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
7146ab97682fd444586ee135912a4210417a1c8781bJason Sams    native int  rsnScriptIntrinsicCreate(int con, int id, int eid);
7156ab97682fd444586ee135912a4210417a1c8781bJason Sams    synchronized int nScriptIntrinsicCreate(int id, int eid) {
7166ab97682fd444586ee135912a4210417a1c8781bJason Sams        validate();
7176ab97682fd444586ee135912a4210417a1c8781bJason Sams        return rsnScriptIntrinsicCreate(mContext, id, eid);
7186ab97682fd444586ee135912a4210417a1c8781bJason Sams    }
7196ab97682fd444586ee135912a4210417a1c8781bJason Sams
72008a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    native int  rsnScriptKernelIDCreate(int con, int sid, int slot, int sig);
72108a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    synchronized int nScriptKernelIDCreate(int sid, int slot, int sig) {
72208a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams        validate();
72308a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams        return rsnScriptKernelIDCreate(mContext, sid, slot, sig);
72408a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    }
72508a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams
72608a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    native int  rsnScriptFieldIDCreate(int con, int sid, int slot);
72708a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    synchronized int nScriptFieldIDCreate(int sid, int slot) {
72808a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams        validate();
72908a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams        return rsnScriptFieldIDCreate(mContext, sid, slot);
73008a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    }
73108a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams
73208a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    native int  rsnScriptGroupCreate(int con, int[] kernels, int[] src, int[] dstk, int[] dstf, int[] types);
73308a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    synchronized int nScriptGroupCreate(int[] kernels, int[] src, int[] dstk, int[] dstf, int[] types) {
73408a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams        validate();
73508a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams        return rsnScriptGroupCreate(mContext, kernels, src, dstk, dstf, types);
73608a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    }
73708a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams
73808a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    native void rsnScriptGroupSetInput(int con, int group, int kernel, int alloc);
73908a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    synchronized void nScriptGroupSetInput(int group, int kernel, int alloc) {
74008a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams        validate();
74108a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams        rsnScriptGroupSetInput(mContext, group, kernel, alloc);
74208a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    }
74308a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams
74408a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    native void rsnScriptGroupSetOutput(int con, int group, int kernel, int alloc);
74508a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    synchronized void nScriptGroupSetOutput(int group, int kernel, int alloc) {
74608a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams        validate();
74708a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams        rsnScriptGroupSetOutput(mContext, group, kernel, alloc);
74808a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    }
74908a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams
75008a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    native void rsnScriptGroupExecute(int con, int group);
75108a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    synchronized void nScriptGroupExecute(int group) {
75208a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams        validate();
75308a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams        rsnScriptGroupExecute(mContext, group);
75408a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    }
75508a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams
756a89094aa3bc059c6e03b20b4c5b1ede4582f3da9Alex Sakhartchouk    native int  rsnSamplerCreate(int con, int magFilter, int minFilter,
757a89094aa3bc059c6e03b20b4c5b1ede4582f3da9Alex Sakhartchouk                                 int wrapS, int wrapT, int wrapR, float aniso);
758a89094aa3bc059c6e03b20b4c5b1ede4582f3da9Alex Sakhartchouk    synchronized int nSamplerCreate(int magFilter, int minFilter,
759a89094aa3bc059c6e03b20b4c5b1ede4582f3da9Alex Sakhartchouk                                 int wrapS, int wrapT, int wrapR, float aniso) {
760d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
761a89094aa3bc059c6e03b20b4c5b1ede4582f3da9Alex Sakhartchouk        return rsnSamplerCreate(mContext, magFilter, minFilter, wrapS, wrapT, wrapR, aniso);
7622e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
7632e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
764331bf9b14b1c5c1e88f5c4092b6e24fae887fb3bJason Sams    native int  rsnProgramStoreCreate(int con, boolean r, boolean g, boolean b, boolean a,
765331bf9b14b1c5c1e88f5c4092b6e24fae887fb3bJason Sams                                      boolean depthMask, boolean dither,
766331bf9b14b1c5c1e88f5c4092b6e24fae887fb3bJason Sams                                      int srcMode, int dstMode, int depthFunc);
767331bf9b14b1c5c1e88f5c4092b6e24fae887fb3bJason Sams    synchronized int nProgramStoreCreate(boolean r, boolean g, boolean b, boolean a,
768331bf9b14b1c5c1e88f5c4092b6e24fae887fb3bJason Sams                                         boolean depthMask, boolean dither,
769331bf9b14b1c5c1e88f5c4092b6e24fae887fb3bJason Sams                                         int srcMode, int dstMode, int depthFunc) {
770d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
771bd184c55850997a5c5e285357998dadbe95b7b5dJason Sams        return rsnProgramStoreCreate(mContext, r, g, b, a, depthMask, dither, srcMode,
772bd184c55850997a5c5e285357998dadbe95b7b5dJason Sams                                     dstMode, depthFunc);
7732e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
7742e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
77594aaed38467c71a6c804f0e18b41346a4013c25bJason Sams    native int  rsnProgramRasterCreate(int con, boolean pointSprite, int cullMode);
77694aaed38467c71a6c804f0e18b41346a4013c25bJason Sams    synchronized int nProgramRasterCreate(boolean pointSprite, int cullMode) {
777d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
77894aaed38467c71a6c804f0e18b41346a4013c25bJason Sams        return rsnProgramRasterCreate(mContext, pointSprite, cullMode);
7792e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
7802e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
7812e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnProgramBindConstants(int con, int pv, int slot, int mID);
7822e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nProgramBindConstants(int pv, int slot, int mID) {
783d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
7842e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnProgramBindConstants(mContext, pv, slot, mID);
7852e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
7862e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnProgramBindTexture(int con, int vpf, int slot, int a);
7872e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nProgramBindTexture(int vpf, int slot, int a) {
788d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
7892e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnProgramBindTexture(mContext, vpf, slot, a);
7902e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
7912e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnProgramBindSampler(int con, int vpf, int slot, int s);
7922e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nProgramBindSampler(int vpf, int slot, int s) {
793d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
7942e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnProgramBindSampler(mContext, vpf, slot, s);
7952e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
7962123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk    native int  rsnProgramFragmentCreate(int con, String shader, String[] texNames, int[] params);
7972123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk    synchronized int nProgramFragmentCreate(String shader, String[] texNames, int[] params) {
798d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
7992123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk        return rsnProgramFragmentCreate(mContext, shader, texNames, params);
8002e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
8012123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk    native int  rsnProgramVertexCreate(int con, String shader, String[] texNames, int[] params);
8022123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk    synchronized int nProgramVertexCreate(String shader, String[] texNames, int[] params) {
803d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
8042123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk        return rsnProgramVertexCreate(mContext, shader, texNames, params);
8052e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
8062e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
80725999a08a6652ff5d7d0973f279f1e92e04b3506Alex Sakhartchouk    native int  rsnMeshCreate(int con, int[] vtx, int[] idx, int[] prim);
80825999a08a6652ff5d7d0973f279f1e92e04b3506Alex Sakhartchouk    synchronized int nMeshCreate(int[] vtx, int[] idx, int[] prim) {
809d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
81025999a08a6652ff5d7d0973f279f1e92e04b3506Alex Sakhartchouk        return rsnMeshCreate(mContext, vtx, idx, prim);
8119d71e2180062931416092f26276a07e55b318f62Alex Sakhartchouk    }
8122e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnMeshGetVertexBufferCount(int con, int id);
8132e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nMeshGetVertexBufferCount(int id) {
814d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
8152e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnMeshGetVertexBufferCount(mContext, id);
8162e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
8172e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnMeshGetIndexCount(int con, int id);
8182e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nMeshGetIndexCount(int id) {
819d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
8202e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnMeshGetIndexCount(mContext, id);
8212e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
8222e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnMeshGetVertices(int con, int id, int[] vtxIds, int vtxIdCount);
8232e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nMeshGetVertices(int id, int[] vtxIds, int vtxIdCount) {
824d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
8252e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnMeshGetVertices(mContext, id, vtxIds, vtxIdCount);
8262e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
8272e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnMeshGetIndices(int con, int id, int[] idxIds, int[] primitives, int vtxIdCount);
8282e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nMeshGetIndices(int id, int[] idxIds, int[] primitives, int vtxIdCount) {
829d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
8302e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnMeshGetIndices(mContext, id, idxIds, primitives, vtxIdCount);
8312e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
8322e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
833f15ed0124ea7f7f87e4188a1dd15cc4917a62ee9Jason Sams    native int  rsnPathCreate(int con, int prim, boolean isStatic, int vtx, int loop, float q);
834f15ed0124ea7f7f87e4188a1dd15cc4917a62ee9Jason Sams    synchronized int nPathCreate(int prim, boolean isStatic, int vtx, int loop, float q) {
835f15ed0124ea7f7f87e4188a1dd15cc4917a62ee9Jason Sams        validate();
836f15ed0124ea7f7f87e4188a1dd15cc4917a62ee9Jason Sams        return rsnPathCreate(mContext, prim, isStatic, vtx, loop, q);
837f15ed0124ea7f7f87e4188a1dd15cc4917a62ee9Jason Sams    }
83860aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
839bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    int     mDev;
840bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    int     mContext;
841650a3eb7d621dc8e81573142a4498bbd07bcde27Romain Guy    @SuppressWarnings({"FieldCanBeLocal"})
842bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    MessageThread mMessageThread;
84360aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
8448cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_U8;
8458cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_I8;
8468cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_U16;
8478cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_I16;
8488cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_U32;
8498cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_I32;
85052d836332f6aae74ed97fda1b53681f36710af64Stephen Hines    Element mElement_U64;
851ef1dac28d3bf98bd61cd9874fb3ccab42105e9b6Stephen Hines    Element mElement_I64;
8528cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_F32;
85302f41705199336f808ece50d81585450e7f8f61fStephen Hines    Element mElement_F64;
854f110d4b787b91dabe968a812e76e5c1f8d953487Jason Sams    Element mElement_BOOLEAN;
8558cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams
8568cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_ELEMENT;
8578cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_TYPE;
8588cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_ALLOCATION;
8598cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_SAMPLER;
8608cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_SCRIPT;
8618cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_MESH;
8628cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_PROGRAM_FRAGMENT;
8638cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_PROGRAM_VERTEX;
8648cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_PROGRAM_RASTER;
8658cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_PROGRAM_STORE;
8663a2914132146f340511425d7f78540098606b512Stephen Hines    Element mElement_FONT;
867a70f416c9cf2fc6cc5e132c1d656ce07441d6b82Jason Sams
8683c0dfbab807a459622aeade4940daddf482dec66Jason Sams    Element mElement_A_8;
8693c0dfbab807a459622aeade4940daddf482dec66Jason Sams    Element mElement_RGB_565;
8703c0dfbab807a459622aeade4940daddf482dec66Jason Sams    Element mElement_RGB_888;
8713c0dfbab807a459622aeade4940daddf482dec66Jason Sams    Element mElement_RGBA_5551;
8723c0dfbab807a459622aeade4940daddf482dec66Jason Sams    Element mElement_RGBA_4444;
8733c0dfbab807a459622aeade4940daddf482dec66Jason Sams    Element mElement_RGBA_8888;
8743c0dfbab807a459622aeade4940daddf482dec66Jason Sams
8758cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_FLOAT_2;
8768cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_FLOAT_3;
8778cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_FLOAT_4;
878836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines
879836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_DOUBLE_2;
880836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_DOUBLE_3;
881836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_DOUBLE_4;
882836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines
883836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_UCHAR_2;
884836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_UCHAR_3;
8858cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_UCHAR_4;
8867d787b4722eaeb79cab42c36060336e092b77b5fJason Sams
887836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_CHAR_2;
888836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_CHAR_3;
889836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_CHAR_4;
890836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines
891836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_USHORT_2;
892836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_USHORT_3;
893836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_USHORT_4;
894836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines
895836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_SHORT_2;
896836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_SHORT_3;
897836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_SHORT_4;
898836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines
899836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_UINT_2;
900836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_UINT_3;
901836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_UINT_4;
902836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines
903836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_INT_2;
904836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_INT_3;
905836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_INT_4;
906836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines
907836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_ULONG_2;
908836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_ULONG_3;
909836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_ULONG_4;
910836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines
911836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_LONG_2;
912836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_LONG_3;
913836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_LONG_4;
914836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines
915932e78e9903342e3494983fd3463084caab4ba42Tim Murray    Element mElement_YUV;
916932e78e9903342e3494983fd3463084caab4ba42Tim Murray
9171d45c47975ab2a8cef6db5a8976276de31e1e8d0Jason Sams    Element mElement_MATRIX_4X4;
9181d45c47975ab2a8cef6db5a8976276de31e1e8d0Jason Sams    Element mElement_MATRIX_3X3;
9191d45c47975ab2a8cef6db5a8976276de31e1e8d0Jason Sams    Element mElement_MATRIX_2X2;
9201d45c47975ab2a8cef6db5a8976276de31e1e8d0Jason Sams
9214d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    Sampler mSampler_CLAMP_NEAREST;
9224d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    Sampler mSampler_CLAMP_LINEAR;
9234d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    Sampler mSampler_CLAMP_LINEAR_MIP_LINEAR;
9244d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    Sampler mSampler_WRAP_NEAREST;
9254d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    Sampler mSampler_WRAP_LINEAR;
9264d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    Sampler mSampler_WRAP_LINEAR_MIP_LINEAR;
9276b9b2caf2bf977508e223792bb5eba75091c232dTim Murray    Sampler mSampler_MIRRORED_REPEAT_NEAREST;
9286b9b2caf2bf977508e223792bb5eba75091c232dTim Murray    Sampler mSampler_MIRRORED_REPEAT_LINEAR;
9296b9b2caf2bf977508e223792bb5eba75091c232dTim Murray    Sampler mSampler_MIRRORED_REPEAT_LINEAR_MIP_LINEAR;
9304d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams
931d36f248eaf06c569010649902df653da1a9e2accAlex Sakhartchouk    ProgramStore mProgramStore_BLEND_NONE_DEPTH_TEST;
932d36f248eaf06c569010649902df653da1a9e2accAlex Sakhartchouk    ProgramStore mProgramStore_BLEND_NONE_DEPTH_NO_DEPTH;
933d36f248eaf06c569010649902df653da1a9e2accAlex Sakhartchouk    ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_TEST;
934d36f248eaf06c569010649902df653da1a9e2accAlex Sakhartchouk    ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_NO_DEPTH;
935d36f248eaf06c569010649902df653da1a9e2accAlex Sakhartchouk
936d36f248eaf06c569010649902df653da1a9e2accAlex Sakhartchouk    ProgramRaster mProgramRaster_CULL_BACK;
937d36f248eaf06c569010649902df653da1a9e2accAlex Sakhartchouk    ProgramRaster mProgramRaster_CULL_FRONT;
938d36f248eaf06c569010649902df653da1a9e2accAlex Sakhartchouk    ProgramRaster mProgramRaster_CULL_NONE;
93932e09b5891da0174f161d99e2d3ebe67d6efa39cAlex Sakhartchouk
94060aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich    ///////////////////////////////////////////////////////////////////////////////////
94143702d8925c54360ad5f9f66b0d35d61d59f6910Jack Palevich    //
94260aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
9439c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines    /**
944c11e25c4e653124def1fb18e203b894f42106cbeTim Murray     * The base class from which an application should derive in order
945c11e25c4e653124def1fb18e203b894f42106cbeTim Murray     * to receive RS messages from scripts. When a script calls {@code
946c11e25c4e653124def1fb18e203b894f42106cbeTim Murray     * rsSendToClient}, the data fields will be filled, and the run
947c11e25c4e653124def1fb18e203b894f42106cbeTim Murray     * method will be called on a separate thread.  This will occur
948c11e25c4e653124def1fb18e203b894f42106cbeTim Murray     * some time after {@code rsSendToClient} completes in the script,
949c11e25c4e653124def1fb18e203b894f42106cbeTim Murray     * as {@code rsSendToClient} is asynchronous. Message handlers are
950c11e25c4e653124def1fb18e203b894f42106cbeTim Murray     * not guaranteed to have completed when {@link
951c11e25c4e653124def1fb18e203b894f42106cbeTim Murray     * android.renderscript.RenderScript#finish} returns.
95227676fe24be7444a174c15df476e49adc5335d03Jason Sams     *
95327676fe24be7444a174c15df476e49adc5335d03Jason Sams     */
954bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    public static class RSMessageHandler implements Runnable {
955516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        protected int[] mData;
956516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        protected int mID;
9571c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams        protected int mLength;
958516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        public void run() {
959516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        }
960516c31911578db8ce53529483c3ded918ac7dc6bJason Sams    }
9619c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines    /**
962c11e25c4e653124def1fb18e203b894f42106cbeTim Murray     * If an application is expecting messages, it should set this
963c11e25c4e653124def1fb18e203b894f42106cbeTim Murray     * field to an instance of {@link RSMessageHandler}.  This
964c11e25c4e653124def1fb18e203b894f42106cbeTim Murray     * instance will receive all the user messages sent from {@code
965c11e25c4e653124def1fb18e203b894f42106cbeTim Murray     * sendToClient} by scripts from this context.
96627676fe24be7444a174c15df476e49adc5335d03Jason Sams     *
96727676fe24be7444a174c15df476e49adc5335d03Jason Sams     */
968bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    RSMessageHandler mMessageCallback = null;
969bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams
970bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    public void setMessageHandler(RSMessageHandler msg) {
971bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams        mMessageCallback = msg;
972bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    }
973bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    public RSMessageHandler getMessageHandler() {
974bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams        return mMessageCallback;
975bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    }
976516c31911578db8ce53529483c3ded918ac7dc6bJason Sams
9779c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines    /**
97802d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams     * Place a message into the message queue to be sent back to the message
97902d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams     * handler once all previous commands have been executed.
980455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams     *
981455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams     * @param id
982455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams     * @param data
983455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams     */
984455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams    public void sendMessage(int id, int[] data) {
985455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams        nContextSendMessage(id, data);
986455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams    }
987455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams
988455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams    /**
989c11e25c4e653124def1fb18e203b894f42106cbeTim Murray     * The runtime error handler base class.  An application should derive from this class
990c11e25c4e653124def1fb18e203b894f42106cbeTim Murray     * if it wishes to install an error handler.  When errors occur at runtime,
991c11e25c4e653124def1fb18e203b894f42106cbeTim Murray     * the fields in this class will be filled, and the run method will be called.
99227676fe24be7444a174c15df476e49adc5335d03Jason Sams     *
99327676fe24be7444a174c15df476e49adc5335d03Jason Sams     */
994bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    public static class RSErrorHandler implements Runnable {
9951c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams        protected String mErrorMessage;
9961c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams        protected int mErrorNum;
9971c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams        public void run() {
9981c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams        }
9991c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams    }
100027676fe24be7444a174c15df476e49adc5335d03Jason Sams
10019c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines    /**
100227676fe24be7444a174c15df476e49adc5335d03Jason Sams     * Application Error handler.  All runtime errors will be dispatched to the
100327676fe24be7444a174c15df476e49adc5335d03Jason Sams     * instance of RSAsyncError set here.  If this field is null a
1004c11e25c4e653124def1fb18e203b894f42106cbeTim Murray     * {@link RSRuntimeException} will instead be thrown with details about the error.
100527676fe24be7444a174c15df476e49adc5335d03Jason Sams     * This will cause program termaination.
100627676fe24be7444a174c15df476e49adc5335d03Jason Sams     *
100727676fe24be7444a174c15df476e49adc5335d03Jason Sams     */
1008bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    RSErrorHandler mErrorCallback = null;
1009bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams
1010bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    public void setErrorHandler(RSErrorHandler msg) {
1011bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams        mErrorCallback = msg;
1012bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    }
1013bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    public RSErrorHandler getErrorHandler() {
1014bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams        return mErrorCallback;
1015bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    }
10161c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams
10179c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines    /**
1018c11e25c4e653124def1fb18e203b894f42106cbeTim Murray     * RenderScript worker thread priority enumeration.  The default value is
1019c11e25c4e653124def1fb18e203b894f42106cbeTim Murray     * NORMAL.  Applications wishing to do background processing should set
1020c11e25c4e653124def1fb18e203b894f42106cbeTim Murray     * their priority to LOW to avoid starving forground processes.
102127676fe24be7444a174c15df476e49adc5335d03Jason Sams     */
10227d787b4722eaeb79cab42c36060336e092b77b5fJason Sams    public enum Priority {
1023260c77a4f741c3db76057cc4ea2ee54fe335ecf9Glenn Kasten        LOW (Process.THREAD_PRIORITY_BACKGROUND + (5 * Process.THREAD_PRIORITY_LESS_FAVORABLE)),
1024260c77a4f741c3db76057cc4ea2ee54fe335ecf9Glenn Kasten        NORMAL (Process.THREAD_PRIORITY_DISPLAY);
10257d787b4722eaeb79cab42c36060336e092b77b5fJason Sams
10267d787b4722eaeb79cab42c36060336e092b77b5fJason Sams        int mID;
10277d787b4722eaeb79cab42c36060336e092b77b5fJason Sams        Priority(int id) {
10287d787b4722eaeb79cab42c36060336e092b77b5fJason Sams            mID = id;
10297d787b4722eaeb79cab42c36060336e092b77b5fJason Sams        }
10307d787b4722eaeb79cab42c36060336e092b77b5fJason Sams    }
10317d787b4722eaeb79cab42c36060336e092b77b5fJason Sams
1032771bebb94054d06f97284379c93a2620613513c3Jason Sams    void validate() {
1033771bebb94054d06f97284379c93a2620613513c3Jason Sams        if (mContext == 0) {
1034c1d6210fb5cc558ccea95a59a2b33bb9015fc7deJason Sams            throw new RSInvalidStateException("Calling RS with no Context active.");
1035771bebb94054d06f97284379c93a2620613513c3Jason Sams        }
1036771bebb94054d06f97284379c93a2620613513c3Jason Sams    }
1037771bebb94054d06f97284379c93a2620613513c3Jason Sams
103827676fe24be7444a174c15df476e49adc5335d03Jason Sams
10399c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines    /**
104027676fe24be7444a174c15df476e49adc5335d03Jason Sams     * Change the priority of the worker threads for this context.
104127676fe24be7444a174c15df476e49adc5335d03Jason Sams     *
104227676fe24be7444a174c15df476e49adc5335d03Jason Sams     * @param p New priority to be set.
104327676fe24be7444a174c15df476e49adc5335d03Jason Sams     */
1044bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    public void setPriority(Priority p) {
10455dbfe93b3f15f3a837836d024958635fd8f9ad14Jason Sams        validate();
10467d787b4722eaeb79cab42c36060336e092b77b5fJason Sams        nContextSetPriority(p.mID);
10477d787b4722eaeb79cab42c36060336e092b77b5fJason Sams    }
10487d787b4722eaeb79cab42c36060336e092b77b5fJason Sams
1049bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    static class MessageThread extends Thread {
1050516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        RenderScript mRS;
1051516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        boolean mRun = true;
1052bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams        int[] mAuxData = new int[2];
10531c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams
1054bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams        static final int RS_MESSAGE_TO_CLIENT_NONE = 0;
1055bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams        static final int RS_MESSAGE_TO_CLIENT_EXCEPTION = 1;
1056bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams        static final int RS_MESSAGE_TO_CLIENT_RESIZE = 2;
1057bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams        static final int RS_MESSAGE_TO_CLIENT_ERROR = 3;
1058bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams        static final int RS_MESSAGE_TO_CLIENT_USER = 4;
1059739c8263a10d34f5acba7fce2052012d1545d10bJason Sams        static final int RS_MESSAGE_TO_CLIENT_NEW_BUFFER = 5;
1060516c31911578db8ce53529483c3ded918ac7dc6bJason Sams
106142028a87568c2b7b5ff3691df7c345bbc5802adeStephen Hines        static final int RS_ERROR_FATAL_DEBUG = 0x0800;
1062bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams        static final int RS_ERROR_FATAL_UNKNOWN = 0x1000;
1063add9d9633205f76cc34f04368b8482c2c369ba63Jason Sams
1064516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        MessageThread(RenderScript rs) {
1065516c31911578db8ce53529483c3ded918ac7dc6bJason Sams            super("RSMessageThread");
1066516c31911578db8ce53529483c3ded918ac7dc6bJason Sams            mRS = rs;
1067516c31911578db8ce53529483c3ded918ac7dc6bJason Sams
1068516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        }
1069516c31911578db8ce53529483c3ded918ac7dc6bJason Sams
1070516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        public void run() {
1071516c31911578db8ce53529483c3ded918ac7dc6bJason Sams            // This function is a temporary solution.  The final solution will
1072516c31911578db8ce53529483c3ded918ac7dc6bJason Sams            // used typed allocations where the message id is the type indicator.
1073516c31911578db8ce53529483c3ded918ac7dc6bJason Sams            int[] rbuf = new int[16];
10742e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams            mRS.nContextInitToClient(mRS.mContext);
1075516c31911578db8ce53529483c3ded918ac7dc6bJason Sams            while(mRun) {
10761d45c47975ab2a8cef6db5a8976276de31e1e8d0Jason Sams                rbuf[0] = 0;
1077edbfabdb98a2974f973d6c042e6efd547dc02fc5Jason Sams                int msg = mRS.nContextPeekMessage(mRS.mContext, mAuxData);
1078bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams                int size = mAuxData[1];
1079bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams                int subID = mAuxData[0];
10801c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams
10811c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                if (msg == RS_MESSAGE_TO_CLIENT_USER) {
10821c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                    if ((size>>2) >= rbuf.length) {
10831c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                        rbuf = new int[(size + 3) >> 2];
10841c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                    }
1085edbfabdb98a2974f973d6c042e6efd547dc02fc5Jason Sams                    if (mRS.nContextGetUserMessage(mRS.mContext, rbuf) !=
1086edbfabdb98a2974f973d6c042e6efd547dc02fc5Jason Sams                        RS_MESSAGE_TO_CLIENT_USER) {
1087c11e25c4e653124def1fb18e203b894f42106cbeTim Murray                        throw new RSDriverException("Error processing message from RenderScript.");
1088edbfabdb98a2974f973d6c042e6efd547dc02fc5Jason Sams                    }
10891c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams
10901c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                    if(mRS.mMessageCallback != null) {
10911c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                        mRS.mMessageCallback.mData = rbuf;
10921c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                        mRS.mMessageCallback.mID = subID;
10931c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                        mRS.mMessageCallback.mLength = size;
10941c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                        mRS.mMessageCallback.run();
10951d45c47975ab2a8cef6db5a8976276de31e1e8d0Jason Sams                    } else {
10961c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                        throw new RSInvalidStateException("Received a message from the script with no message handler installed.");
1097516c31911578db8ce53529483c3ded918ac7dc6bJason Sams                    }
1098ab98bb6e8b95bef7415c1ad239be71f93322fbadStephen Hines                    continue;
1099516c31911578db8ce53529483c3ded918ac7dc6bJason Sams                }
11001c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams
11011c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                if (msg == RS_MESSAGE_TO_CLIENT_ERROR) {
11021c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                    String e = mRS.nContextGetErrorMessage(mRS.mContext);
11031c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams
110442028a87568c2b7b5ff3691df7c345bbc5802adeStephen Hines                    // Throw RSRuntimeException under the following conditions:
110542028a87568c2b7b5ff3691df7c345bbc5802adeStephen Hines                    //
110642028a87568c2b7b5ff3691df7c345bbc5802adeStephen Hines                    // 1) It is an unknown fatal error.
110742028a87568c2b7b5ff3691df7c345bbc5802adeStephen Hines                    // 2) It is a debug fatal error, and we are not in a
110842028a87568c2b7b5ff3691df7c345bbc5802adeStephen Hines                    //    debug context.
110942028a87568c2b7b5ff3691df7c345bbc5802adeStephen Hines                    // 3) It is a debug fatal error, and we do not have an
111042028a87568c2b7b5ff3691df7c345bbc5802adeStephen Hines                    //    error callback.
111142028a87568c2b7b5ff3691df7c345bbc5802adeStephen Hines                    if (subID >= RS_ERROR_FATAL_UNKNOWN ||
111242028a87568c2b7b5ff3691df7c345bbc5802adeStephen Hines                        (subID >= RS_ERROR_FATAL_DEBUG &&
111342028a87568c2b7b5ff3691df7c345bbc5802adeStephen Hines                         (mRS.mContextType != ContextType.DEBUG ||
111442028a87568c2b7b5ff3691df7c345bbc5802adeStephen Hines                          mRS.mErrorCallback == null))) {
1115add9d9633205f76cc34f04368b8482c2c369ba63Jason Sams                        throw new RSRuntimeException("Fatal error " + subID + ", details: " + e);
1116add9d9633205f76cc34f04368b8482c2c369ba63Jason Sams                    }
1117add9d9633205f76cc34f04368b8482c2c369ba63Jason Sams
11181c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                    if(mRS.mErrorCallback != null) {
11191c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                        mRS.mErrorCallback.mErrorMessage = e;
11201c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                        mRS.mErrorCallback.mErrorNum = subID;
11211c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                        mRS.mErrorCallback.run();
11221c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                    } else {
1123a4b7bc97862e01d38b483524f1d1cf433d29e294Jason Sams                        android.util.Log.e(LOG_TAG, "non fatal RS error, " + e);
1124be74bdd2349095f203ae0fddcc4816bfbd56bc5dStephen Hines                        // Do not throw here. In these cases, we do not have
1125be74bdd2349095f203ae0fddcc4816bfbd56bc5dStephen Hines                        // a fatal error.
11261c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                    }
11271c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                    continue;
11281c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                }
11291c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams
1130739c8263a10d34f5acba7fce2052012d1545d10bJason Sams                if (msg == RS_MESSAGE_TO_CLIENT_NEW_BUFFER) {
1131739c8263a10d34f5acba7fce2052012d1545d10bJason Sams                    Allocation.sendBufferNotification(subID);
1132739c8263a10d34f5acba7fce2052012d1545d10bJason Sams                    continue;
1133739c8263a10d34f5acba7fce2052012d1545d10bJason Sams                }
1134739c8263a10d34f5acba7fce2052012d1545d10bJason Sams
11351c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                // 2: teardown.
11361c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                // But we want to avoid starving other threads during
11371c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                // teardown by yielding until the next line in the destructor
11381c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                // can execute to set mRun = false
11391c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                try {
11401c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                    sleep(1, 0);
11411c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                } catch(InterruptedException e) {
1142516c31911578db8ce53529483c3ded918ac7dc6bJason Sams                }
1143516c31911578db8ce53529483c3ded918ac7dc6bJason Sams            }
1144da67debe22159fdf0bbeca6340766ebe2b8e67a3Tim Murray            //Log.d(LOG_TAG, "MessageThread exiting.");
1145516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        }
1146516c31911578db8ce53529483c3ded918ac7dc6bJason Sams    }
1147516c31911578db8ce53529483c3ded918ac7dc6bJason Sams
11486b32fab1dbfd8bc1cc176557fe0a7b2ebd4966bdShih-wei Liao    RenderScript(Context ctx) {
114942028a87568c2b7b5ff3691df7c345bbc5802adeStephen Hines        mContextType = ContextType.NORMAL;
11501a4e1f3efd077f3a61038aedab84dc84c9c44d19Jason Sams        if (ctx != null) {
11511a4e1f3efd077f3a61038aedab84dc84c9c44d19Jason Sams            mApplicationContext = ctx.getApplicationContext();
11521a4e1f3efd077f3a61038aedab84dc84c9c44d19Jason Sams        }
1153ff7256e757502279b1777127a12eba235be679aeJason Sams        mRWLock = new ReentrantReadWriteLock();
115460aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich    }
115560aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
11569c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines    /**
11576b32fab1dbfd8bc1cc176557fe0a7b2ebd4966bdShih-wei Liao     * Gets the application context associated with the RenderScript context.
115827676fe24be7444a174c15df476e49adc5335d03Jason Sams     *
11596b32fab1dbfd8bc1cc176557fe0a7b2ebd4966bdShih-wei Liao     * @return The application context.
11606b32fab1dbfd8bc1cc176557fe0a7b2ebd4966bdShih-wei Liao     */
11616b32fab1dbfd8bc1cc176557fe0a7b2ebd4966bdShih-wei Liao    public final Context getApplicationContext() {
11626b32fab1dbfd8bc1cc176557fe0a7b2ebd4966bdShih-wei Liao        return mApplicationContext;
11636b32fab1dbfd8bc1cc176557fe0a7b2ebd4966bdShih-wei Liao    }
11646b32fab1dbfd8bc1cc176557fe0a7b2ebd4966bdShih-wei Liao
11659c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines    /**
1166add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams     * @hide
1167add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams     */
1168add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams    public static RenderScript create(Context ctx, int sdkVersion) {
1169add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams        return create(ctx, sdkVersion, ContextType.NORMAL);
1170add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams    }
1171add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams
1172add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams    /**
1173c11e25c4e653124def1fb18e203b894f42106cbeTim Murray     * Create a RenderScript context.
117427676fe24be7444a174c15df476e49adc5335d03Jason Sams     *
11751a4e1f3efd077f3a61038aedab84dc84c9c44d19Jason Sams     * @hide
11766b32fab1dbfd8bc1cc176557fe0a7b2ebd4966bdShih-wei Liao     * @param ctx The context.
117727676fe24be7444a174c15df476e49adc5335d03Jason Sams     * @return RenderScript
117827676fe24be7444a174c15df476e49adc5335d03Jason Sams     */
1179add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams    public static RenderScript create(Context ctx, int sdkVersion, ContextType ct) {
1180e4d9a01bfc7451afff1ed399a5801c7aa2af2831Dan Morrill        if (!sInitialized) {
1181e4d9a01bfc7451afff1ed399a5801c7aa2af2831Dan Morrill            Log.e(LOG_TAG, "RenderScript.create() called when disabled; someone is likely to crash");
1182e4d9a01bfc7451afff1ed399a5801c7aa2af2831Dan Morrill            return null;
1183e4d9a01bfc7451afff1ed399a5801c7aa2af2831Dan Morrill        }
1184e4d9a01bfc7451afff1ed399a5801c7aa2af2831Dan Morrill
11856b32fab1dbfd8bc1cc176557fe0a7b2ebd4966bdShih-wei Liao        RenderScript rs = new RenderScript(ctx);
1186704ff64b099406bb328898a7443921f22dbffd6dJason Sams
1187704ff64b099406bb328898a7443921f22dbffd6dJason Sams        rs.mDev = rs.nDeviceCreate();
1188add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams        rs.mContext = rs.nContextCreate(rs.mDev, 0, sdkVersion, ct.mID);
118942028a87568c2b7b5ff3691df7c345bbc5802adeStephen Hines        rs.mContextType = ct;
11902698536b3ff60bfee85e47e4a8d4b25fdfdf4db5Jason Sams        if (rs.mContext == 0) {
11912698536b3ff60bfee85e47e4a8d4b25fdfdf4db5Jason Sams            throw new RSDriverException("Failed to create RS context.");
11922698536b3ff60bfee85e47e4a8d4b25fdfdf4db5Jason Sams        }
1193704ff64b099406bb328898a7443921f22dbffd6dJason Sams        rs.mMessageThread = new MessageThread(rs);
1194704ff64b099406bb328898a7443921f22dbffd6dJason Sams        rs.mMessageThread.start();
1195704ff64b099406bb328898a7443921f22dbffd6dJason Sams        return rs;
1196efd9b6fb2e0f31b50db089352118e5daeb268879Jason Sams    }
1197efd9b6fb2e0f31b50db089352118e5daeb268879Jason Sams
11989c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines    /**
1199c11e25c4e653124def1fb18e203b894f42106cbeTim Murray     * Create a RenderScript context.
12001a4e1f3efd077f3a61038aedab84dc84c9c44d19Jason Sams     *
12011a4e1f3efd077f3a61038aedab84dc84c9c44d19Jason Sams     * @param ctx The context.
12021a4e1f3efd077f3a61038aedab84dc84c9c44d19Jason Sams     * @return RenderScript
12031a4e1f3efd077f3a61038aedab84dc84c9c44d19Jason Sams     */
12041a4e1f3efd077f3a61038aedab84dc84c9c44d19Jason Sams    public static RenderScript create(Context ctx) {
1205add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams        return create(ctx, ContextType.NORMAL);
1206add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams    }
1207add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams
1208add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams    /**
1209c11e25c4e653124def1fb18e203b894f42106cbeTim Murray     * Create a RenderScript context.
1210add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams     *
1211add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams     *
1212add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams     * @param ctx The context.
121302d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams     * @param ct The type of context to be created.
1214add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams     * @return RenderScript
1215add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams     */
1216add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams    public static RenderScript create(Context ctx, ContextType ct) {
12171a4e1f3efd077f3a61038aedab84dc84c9c44d19Jason Sams        int v = ctx.getApplicationInfo().targetSdkVersion;
1218add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams        return create(ctx, v, ct);
12191a4e1f3efd077f3a61038aedab84dc84c9c44d19Jason Sams    }
12201a4e1f3efd077f3a61038aedab84dc84c9c44d19Jason Sams
12219c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines    /**
122227676fe24be7444a174c15df476e49adc5335d03Jason Sams     * Print the currently available debugging information about the state of
122327676fe24be7444a174c15df476e49adc5335d03Jason Sams     * the RS context to the log.
122427676fe24be7444a174c15df476e49adc5335d03Jason Sams     *
122527676fe24be7444a174c15df476e49adc5335d03Jason Sams     */
1226bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    public void contextDump() {
12275dbfe93b3f15f3a837836d024958635fd8f9ad14Jason Sams        validate();
1228bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams        nContextDump(0);
1229715333b832fb448c32165c7d97d408a3fa43f7cbJason Sams    }
1230715333b832fb448c32165c7d97d408a3fa43f7cbJason Sams
12319c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines    /**
1232c11e25c4e653124def1fb18e203b894f42106cbeTim Murray     * Wait for any pending asynchronous opeations (such as copies to a RS
1233c11e25c4e653124def1fb18e203b894f42106cbeTim Murray     * allocation or RS script executions) to complete.
123427676fe24be7444a174c15df476e49adc5335d03Jason Sams     *
123527676fe24be7444a174c15df476e49adc5335d03Jason Sams     */
123696ed4cfa62dd09aafb3f9da01e047661b4fe3c95Jason Sams    public void finish() {
123796ed4cfa62dd09aafb3f9da01e047661b4fe3c95Jason Sams        nContextFinish();
123896ed4cfa62dd09aafb3f9da01e047661b4fe3c95Jason Sams    }
123996ed4cfa62dd09aafb3f9da01e047661b4fe3c95Jason Sams
12409c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines    /**
1241c11e25c4e653124def1fb18e203b894f42106cbeTim Murray     * Destroys this RenderScript context.  Once this function is called,
1242c11e25c4e653124def1fb18e203b894f42106cbeTim Murray     * using this context or any objects belonging to this context is
1243c11e25c4e653124def1fb18e203b894f42106cbeTim Murray     * illegal.
124427676fe24be7444a174c15df476e49adc5335d03Jason Sams     *
124527676fe24be7444a174c15df476e49adc5335d03Jason Sams     */
1246f5b4596a383b6ab83f92edecfe054e80b555c2d0Jason Sams    public void destroy() {
12475dbfe93b3f15f3a837836d024958635fd8f9ad14Jason Sams        validate();
1248ff7256e757502279b1777127a12eba235be679aeJason Sams        nContextFinish();
1249ff7256e757502279b1777127a12eba235be679aeJason Sams
12502e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        nContextDeinitToClient(mContext);
1251516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        mMessageThread.mRun = false;
1252a8bf9429b29743b3489817feb21bde2416acc465Jason Sams        try {
1253a8bf9429b29743b3489817feb21bde2416acc465Jason Sams            mMessageThread.join();
1254a8bf9429b29743b3489817feb21bde2416acc465Jason Sams        } catch(InterruptedException e) {
1255a8bf9429b29743b3489817feb21bde2416acc465Jason Sams        }
1256516c31911578db8ce53529483c3ded918ac7dc6bJason Sams
12572e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        nContextDestroy();
1258f5b4596a383b6ab83f92edecfe054e80b555c2d0Jason Sams
1259f5b4596a383b6ab83f92edecfe054e80b555c2d0Jason Sams        nDeviceDestroy(mDev);
1260f5b4596a383b6ab83f92edecfe054e80b555c2d0Jason Sams        mDev = 0;
1261f5b4596a383b6ab83f92edecfe054e80b555c2d0Jason Sams    }
126202fb2cb531035779a25dbf9595e0628ea40585b0Jason Sams
1263a9e7a05b84470257637c97d65f6562aa832c66efJason Sams    boolean isAlive() {
1264a9e7a05b84470257637c97d65f6562aa832c66efJason Sams        return mContext != 0;
1265a9e7a05b84470257637c97d65f6562aa832c66efJason Sams    }
1266a9e7a05b84470257637c97d65f6562aa832c66efJason Sams
1267bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    int safeID(BaseObj o) {
12686b9dec00afec359f091ed353f371f08ff150278aJason Sams        if(o != null) {
1269e07694b24f7d12d72b084b6651356681ebd0efd6Jason Sams            return o.getID(this);
1270d8e4161f114331343b897cbacea927e7e60e7b17Jason Sams        }
12716b9dec00afec359f091ed353f371f08ff150278aJason Sams        return 0;
127260aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich    }
127360aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich}
1274