RenderScript.java revision 6b9b2caf2bf977508e223792bb5eba75091c232d
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;
2136e612a488511940b61f09803b270aa1c61b68e0Jason Sams
226b32fab1dbfd8bc1cc176557fe0a7b2ebd4966bdShih-wei Liaoimport android.content.Context;
234382467a80dd12c6362d57edca7f2367f7ae877cStephen Hinesimport android.content.pm.ApplicationInfo;
244382467a80dd12c6362d57edca7f2367f7ae877cStephen Hinesimport android.content.pm.PackageManager;
25b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchoukimport android.content.res.AssetManager;
26b8c5a84e7c23746a3fc26013e0880d3d95ca6588Jason Samsimport android.graphics.Bitmap;
27650a3eb7d621dc8e81573142a4498bbd07bcde27Romain Guyimport android.graphics.BitmapFactory;
28faa32b33b50ad941f631716dd0915e936bdc3ac5Jason Samsimport android.graphics.SurfaceTexture;
29260c77a4f741c3db76057cc4ea2ee54fe335ecf9Glenn Kastenimport android.os.Process;
3036e612a488511940b61f09803b270aa1c61b68e0Jason Samsimport android.util.Log;
3136e612a488511940b61f09803b270aa1c61b68e0Jason Samsimport android.view.Surface;
3243702d8925c54360ad5f9f66b0d35d61d59f6910Jack Palevich
3360aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
344382467a80dd12c6362d57edca7f2367f7ae877cStephen Hines
359c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines/**
363aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * Renderscript base master class.  An instance of this class creates native
3727676fe24be7444a174c15df476e49adc5335d03Jason Sams * worker threads for processing commands from this object.  This base class
3827676fe24be7444a174c15df476e49adc5335d03Jason Sams * does not provide any extended capabilities beyond simple data processing.
3927676fe24be7444a174c15df476e49adc5335d03Jason Sams * For extended capabilities use derived classes such as RenderScriptGL.
4027676fe24be7444a174c15df476e49adc5335d03Jason Sams *
413aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <div class="special reference">
423aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <h3>Developer Guides</h3>
433aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <p>For more information about creating an application that uses Renderscript, read the
44b47fa1699a02a96d5da8e175966e9584c6bd5565Scott Main * <a href="{@docRoot}guide/topics/renderscript/index.html">Renderscript</a> developer guide.</p>
453aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * </div>
46e29d471e5ca9781d8772d445ec7832e94856fd14Jason Sams **/
4760aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevichpublic class RenderScript {
483bc47d438171dce294e816366d53bc9eca772c5bJason Sams    static final String LOG_TAG = "RenderScript_jni";
49bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    static final boolean DEBUG  = false;
50650a3eb7d621dc8e81573142a4498bbd07bcde27Romain Guy    @SuppressWarnings({"UnusedDeclaration", "deprecation"})
5143a17654cf4bfe7f1ec22bd8b7b32daccdf27c09Joe Onorato    static final boolean LOG_ENABLED = false;
5260aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
536b32fab1dbfd8bc1cc176557fe0a7b2ebd4966bdShih-wei Liao    private Context mApplicationContext;
5460aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
556b32fab1dbfd8bc1cc176557fe0a7b2ebd4966bdShih-wei Liao    /*
5660aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich     * We use a class initializer to allow the native code to cache some
5760aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich     * field offsets.
5860aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich     */
59650a3eb7d621dc8e81573142a4498bbd07bcde27Romain Guy    @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"})
60bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    static boolean sInitialized;
61bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    native static void _nInit();
6260aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
63dba3ba5b5bf6026abceced921b1b0d231b0faefdJason Sams
6460aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich    static {
6560aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich        sInitialized = false;
6660aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich        try {
67e29d471e5ca9781d8772d445ec7832e94856fd14Jason Sams            System.loadLibrary("rs_jni");
6860aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich            _nInit();
6960aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich            sInitialized = true;
7060aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich        } catch (UnsatisfiedLinkError e) {
71fa445b9353972735d8d65e8a936786b1afe9886dJason Sams            Log.e(LOG_TAG, "Error loading RS jni library: " + e);
72fa445b9353972735d8d65e8a936786b1afe9886dJason Sams            throw new RSRuntimeException("Error loading RS jni library: " + e);
7360aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich        }
7460aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich    }
7560aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
762e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    // Non-threadsafe functions.
7736e612a488511940b61f09803b270aa1c61b68e0Jason Sams    native int  nDeviceCreate();
7836e612a488511940b61f09803b270aa1c61b68e0Jason Sams    native void nDeviceDestroy(int dev);
79ebfb436a49673693b98469683451bd9ede797557Jason Sams    native void nDeviceSetConfig(int dev, int param, int value);
80edbfabdb98a2974f973d6c042e6efd547dc02fc5Jason Sams    native int nContextGetUserMessage(int con, int[] data);
811c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams    native String nContextGetErrorMessage(int con);
82edbfabdb98a2974f973d6c042e6efd547dc02fc5Jason Sams    native int  nContextPeekMessage(int con, int[] subID);
832e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void nContextInitToClient(int con);
842e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void nContextDeinitToClient(int con);
852e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
86a6f338ca5f0c8359d1952167858851dd025e47e2Jason Sams    /**
87a6f338ca5f0c8359d1952167858851dd025e47e2Jason Sams     * Name of the file that holds the object cache.
88a6f338ca5f0c8359d1952167858851dd025e47e2Jason Sams     */
89a6f338ca5f0c8359d1952167858851dd025e47e2Jason Sams    private static final String CACHE_PATH = "com.android.renderscript.cache";
901a4e1f3efd077f3a61038aedab84dc84c9c44d19Jason Sams    static String mCachePath;
91a6f338ca5f0c8359d1952167858851dd025e47e2Jason Sams
92a6f338ca5f0c8359d1952167858851dd025e47e2Jason Sams     /**
93a6f338ca5f0c8359d1952167858851dd025e47e2Jason Sams     * Sets the directory to use as a persistent storage for the
94a6f338ca5f0c8359d1952167858851dd025e47e2Jason Sams     * renderscript object file cache.
95a6f338ca5f0c8359d1952167858851dd025e47e2Jason Sams     *
96a6f338ca5f0c8359d1952167858851dd025e47e2Jason Sams     * @hide
97a6f338ca5f0c8359d1952167858851dd025e47e2Jason Sams     * @param cacheDir A directory the current process can write to
98a6f338ca5f0c8359d1952167858851dd025e47e2Jason Sams     */
99a6f338ca5f0c8359d1952167858851dd025e47e2Jason Sams    public static void setupDiskCache(File cacheDir) {
100a6f338ca5f0c8359d1952167858851dd025e47e2Jason Sams        File f = new File(cacheDir, CACHE_PATH);
101a6f338ca5f0c8359d1952167858851dd025e47e2Jason Sams        mCachePath = f.getAbsolutePath();
102a6f338ca5f0c8359d1952167858851dd025e47e2Jason Sams        f.mkdirs();
103a6f338ca5f0c8359d1952167858851dd025e47e2Jason Sams    }
104a6f338ca5f0c8359d1952167858851dd025e47e2Jason Sams
1052e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
1062e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    // Methods below are wrapped to protect the non-threadsafe
1072e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    // lockless fifo.
1084382467a80dd12c6362d57edca7f2367f7ae877cStephen Hines    native int  rsnContextCreateGL(int dev, int ver, int sdkVer,
10911c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams                 int colorMin, int colorPref,
11011c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams                 int alphaMin, int alphaPref,
11111c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams                 int depthMin, int depthPref,
11211c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams                 int stencilMin, int stencilPref,
1132c74ad9aae29cc64fece926f353825a7925792c2Alex Sakhartchouk                 int samplesMin, int samplesPref, float samplesQ, int dpi);
1144382467a80dd12c6362d57edca7f2367f7ae877cStephen Hines    synchronized int nContextCreateGL(int dev, int ver, int sdkVer,
11511c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams                 int colorMin, int colorPref,
11611c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams                 int alphaMin, int alphaPref,
11711c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams                 int depthMin, int depthPref,
11811c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams                 int stencilMin, int stencilPref,
1192c74ad9aae29cc64fece926f353825a7925792c2Alex Sakhartchouk                 int samplesMin, int samplesPref, float samplesQ, int dpi) {
1204382467a80dd12c6362d57edca7f2367f7ae877cStephen Hines        return rsnContextCreateGL(dev, ver, sdkVer, colorMin, colorPref,
12111c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams                                  alphaMin, alphaPref, depthMin, depthPref,
12211c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams                                  stencilMin, stencilPref,
1232c74ad9aae29cc64fece926f353825a7925792c2Alex Sakhartchouk                                  samplesMin, samplesPref, samplesQ, dpi);
1242e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1254382467a80dd12c6362d57edca7f2367f7ae877cStephen Hines    native int  rsnContextCreate(int dev, int ver, int sdkVer);
1264382467a80dd12c6362d57edca7f2367f7ae877cStephen Hines    synchronized int nContextCreate(int dev, int ver, int sdkVer) {
1274382467a80dd12c6362d57edca7f2367f7ae877cStephen Hines        return rsnContextCreate(dev, ver, sdkVer);
1282e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1292e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextDestroy(int con);
1302e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextDestroy() {
131d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
1322e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextDestroy(mContext);
1332e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1342e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextSetSurface(int con, int w, int h, Surface sur);
1352e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextSetSurface(int w, int h, Surface sur) {
136d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
1372e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextSetSurface(mContext, w, h, sur);
1382e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
139faa32b33b50ad941f631716dd0915e936bdc3ac5Jason Sams    native void rsnContextSetSurfaceTexture(int con, int w, int h, SurfaceTexture sur);
140faa32b33b50ad941f631716dd0915e936bdc3ac5Jason Sams    synchronized void nContextSetSurfaceTexture(int w, int h, SurfaceTexture sur) {
141faa32b33b50ad941f631716dd0915e936bdc3ac5Jason Sams        validate();
142faa32b33b50ad941f631716dd0915e936bdc3ac5Jason Sams        rsnContextSetSurfaceTexture(mContext, w, h, sur);
143faa32b33b50ad941f631716dd0915e936bdc3ac5Jason Sams    }
1442e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextSetPriority(int con, int p);
1452e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextSetPriority(int p) {
146d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
1472e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextSetPriority(mContext, p);
1482e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1492e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextDump(int con, int bits);
1502e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextDump(int bits) {
151d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
1522e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextDump(mContext, bits);
1532e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1542e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextFinish(int con);
1552e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextFinish() {
156d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
1572e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextFinish(mContext);
1582e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1592e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
160455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams    native void rsnContextSendMessage(int con, int id, int[] data);
161455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams    synchronized void nContextSendMessage(int id, int[] data) {
162455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams        validate();
163455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams        rsnContextSendMessage(mContext, id, data);
164455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams    }
165455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams
1662e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextBindRootScript(int con, int script);
1672e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextBindRootScript(int script) {
168d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
1692e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextBindRootScript(mContext, script);
1702e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1712e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextBindSampler(int con, int sampler, int slot);
1722e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextBindSampler(int sampler, int slot) {
173d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
1742e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextBindSampler(mContext, sampler, slot);
1752e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1762e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextBindProgramStore(int con, int pfs);
1772e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextBindProgramStore(int pfs) {
178d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
1792e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextBindProgramStore(mContext, pfs);
1802e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1812e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextBindProgramFragment(int con, int pf);
1822e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextBindProgramFragment(int pf) {
183d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
1842e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextBindProgramFragment(mContext, pf);
1852e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1862e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextBindProgramVertex(int con, int pv);
1872e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextBindProgramVertex(int pv) {
188d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
1892e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextBindProgramVertex(mContext, pv);
1902e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1912e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextBindProgramRaster(int con, int pr);
1922e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextBindProgramRaster(int pr) {
193d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
1942e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextBindProgramRaster(mContext, pr);
1952e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1962e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextPause(int con);
1972e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextPause() {
198d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
1992e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextPause(mContext);
2002e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2012e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextResume(int con);
2022e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextResume() {
203d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
2042e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextResume(mContext);
2052e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2062e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
2072e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAssignName(int con, int obj, byte[] name);
2082e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAssignName(int obj, byte[] name) {
209d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
2102e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAssignName(mContext, obj, name);
2112e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2122e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native String rsnGetName(int con, int obj);
2132e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized String nGetName(int obj) {
214d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
2152e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnGetName(mContext, obj);
2162e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2172e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnObjDestroy(int con, int id);
2182e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nObjDestroy(int id) {
219d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        // There is a race condition here.  The calling code may be run
220d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        // by the gc while teardown is occuring.  This protects againts
221d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        // deleting dead objects.
222d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        if (mContext != 0) {
223d1ac98149737299513da1357e36f68cbb6d74425Jason Sams            rsnObjDestroy(mContext, id);
224d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        }
2252e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2262e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
2272e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnElementCreate(int con, int type, int kind, boolean norm, int vecSize);
2282e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nElementCreate(int type, int kind, boolean norm, int vecSize) {
229d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
2302e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnElementCreate(mContext, type, kind, norm, vecSize);
2312e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
23270d4e5024298f71edb3b04867e05568f5495b4ceJason Sams    native int  rsnElementCreate2(int con, int[] elements, String[] names, int[] arraySizes);
23370d4e5024298f71edb3b04867e05568f5495b4ceJason Sams    synchronized int nElementCreate2(int[] elements, String[] names, int[] arraySizes) {
234d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
23570d4e5024298f71edb3b04867e05568f5495b4ceJason Sams        return rsnElementCreate2(mContext, elements, names, arraySizes);
2362e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2372e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnElementGetNativeData(int con, int id, int[] elementData);
2382e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nElementGetNativeData(int id, int[] elementData) {
239d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
2402e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnElementGetNativeData(mContext, id, elementData);
2412e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2427d5f5e7c8943e043a422ad51c85d4e1684c37e28Alex Sakhartchouk    native void rsnElementGetSubElements(int con, int id,
2437d5f5e7c8943e043a422ad51c85d4e1684c37e28Alex Sakhartchouk                                         int[] IDs, String[] names, int[] arraySizes);
2447d5f5e7c8943e043a422ad51c85d4e1684c37e28Alex Sakhartchouk    synchronized void nElementGetSubElements(int id, int[] IDs, String[] names, int[] arraySizes) {
245d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
2467d5f5e7c8943e043a422ad51c85d4e1684c37e28Alex Sakhartchouk        rsnElementGetSubElements(mContext, id, IDs, names, arraySizes);
2472e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2482e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
249b109cc78616abee7291eb42094cd156b5db3355dJason Sams    native int rsnTypeCreate(int con, int eid, int x, int y, int z, boolean mips, boolean faces, int yuv);
250b109cc78616abee7291eb42094cd156b5db3355dJason Sams    synchronized int nTypeCreate(int eid, int x, int y, int z, boolean mips, boolean faces, int yuv) {
251d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
252b109cc78616abee7291eb42094cd156b5db3355dJason Sams        return rsnTypeCreate(mContext, eid, x, y, z, mips, faces, yuv);
2532e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2542e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnTypeGetNativeData(int con, int id, int[] typeData);
2552e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nTypeGetNativeData(int id, int[] typeData) {
256d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
2572e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnTypeGetNativeData(mContext, id, typeData);
2582e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2592e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
260857d0c7017da763a420e825fffa2f260eb982c97Jason Sams    native int  rsnAllocationCreateTyped(int con, int type, int mip, int usage, int pointer);
261857d0c7017da763a420e825fffa2f260eb982c97Jason Sams    synchronized int nAllocationCreateTyped(int type, int mip, int usage, int pointer) {
262d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
263857d0c7017da763a420e825fffa2f260eb982c97Jason Sams        return rsnAllocationCreateTyped(mContext, type, mip, usage, pointer);
2642e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2655476b450e50939940dcf3f15c92335cee2fc572dJason Sams    native int  rsnAllocationCreateFromBitmap(int con, int type, int mip, Bitmap bmp, int usage);
2665476b450e50939940dcf3f15c92335cee2fc572dJason Sams    synchronized int nAllocationCreateFromBitmap(int type, int mip, Bitmap bmp, int usage) {
267d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
2685476b450e50939940dcf3f15c92335cee2fc572dJason Sams        return rsnAllocationCreateFromBitmap(mContext, type, mip, bmp, usage);
26926ae3904e8050eae655722caf93ee5d3f0ab195aAlex Sakhartchouk    }
270a314551d69098537337c970da615a8f8af58e1f1Tim Murray
271a314551d69098537337c970da615a8f8af58e1f1Tim Murray    native int  rsnAllocationCreateBitmapBackedAllocation(int con, int type, int mip, Bitmap bmp, int usage);
272a314551d69098537337c970da615a8f8af58e1f1Tim Murray    synchronized int nAllocationCreateBitmapBackedAllocation(int type, int mip, Bitmap bmp, int usage) {
273a314551d69098537337c970da615a8f8af58e1f1Tim Murray        validate();
274a314551d69098537337c970da615a8f8af58e1f1Tim Murray        return rsnAllocationCreateBitmapBackedAllocation(mContext, type, mip, bmp, usage);
275a314551d69098537337c970da615a8f8af58e1f1Tim Murray    }
276a314551d69098537337c970da615a8f8af58e1f1Tim Murray
277a314551d69098537337c970da615a8f8af58e1f1Tim Murray
2785476b450e50939940dcf3f15c92335cee2fc572dJason Sams    native int  rsnAllocationCubeCreateFromBitmap(int con, int type, int mip, Bitmap bmp, int usage);
2795476b450e50939940dcf3f15c92335cee2fc572dJason Sams    synchronized int nAllocationCubeCreateFromBitmap(int type, int mip, Bitmap bmp, int usage) {
280d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
2815476b450e50939940dcf3f15c92335cee2fc572dJason Sams        return rsnAllocationCubeCreateFromBitmap(mContext, type, mip, bmp, usage);
28267f2e442a31b8395e3c1951f8e91139ec7f2be99Alex Sakhartchouk    }
2832e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnAllocationCreateBitmapRef(int con, int type, Bitmap bmp);
2842e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nAllocationCreateBitmapRef(int type, Bitmap bmp) {
285d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
2862e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnAllocationCreateBitmapRef(mContext, type, bmp);
2872e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2885476b450e50939940dcf3f15c92335cee2fc572dJason Sams    native int  rsnAllocationCreateFromAssetStream(int con, int mips, int assetStream, int usage);
2895476b450e50939940dcf3f15c92335cee2fc572dJason Sams    synchronized int nAllocationCreateFromAssetStream(int mips, int assetStream, int usage) {
290d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
2915476b450e50939940dcf3f15c92335cee2fc572dJason Sams        return rsnAllocationCreateFromAssetStream(mContext, mips, assetStream, usage);
2925476b450e50939940dcf3f15c92335cee2fc572dJason Sams    }
2935476b450e50939940dcf3f15c92335cee2fc572dJason Sams
2944ef6650bd05a39a09958ea1db92f120ea4949cb1Jason Sams    native void  rsnAllocationCopyToBitmap(int con, int alloc, Bitmap bmp);
2954ef6650bd05a39a09958ea1db92f120ea4949cb1Jason Sams    synchronized void nAllocationCopyToBitmap(int alloc, Bitmap bmp) {
296d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
2974ef6650bd05a39a09958ea1db92f120ea4949cb1Jason Sams        rsnAllocationCopyToBitmap(mContext, alloc, bmp);
2984ef6650bd05a39a09958ea1db92f120ea4949cb1Jason Sams    }
2994ef6650bd05a39a09958ea1db92f120ea4949cb1Jason Sams
3004ef6650bd05a39a09958ea1db92f120ea4949cb1Jason Sams
3015476b450e50939940dcf3f15c92335cee2fc572dJason Sams    native void rsnAllocationSyncAll(int con, int alloc, int src);
3025476b450e50939940dcf3f15c92335cee2fc572dJason Sams    synchronized void nAllocationSyncAll(int alloc, int src) {
303d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
3045476b450e50939940dcf3f15c92335cee2fc572dJason Sams        rsnAllocationSyncAll(mContext, alloc, src);
3055476b450e50939940dcf3f15c92335cee2fc572dJason Sams    }
306615e7cee03d1a53072b0369fa9f247811ac56845Jason Sams    native int rsnAllocationGetSurfaceTextureID(int con, int alloc);
307615e7cee03d1a53072b0369fa9f247811ac56845Jason Sams    synchronized int nAllocationGetSurfaceTextureID(int alloc) {
308615e7cee03d1a53072b0369fa9f247811ac56845Jason Sams        validate();
309615e7cee03d1a53072b0369fa9f247811ac56845Jason Sams        return rsnAllocationGetSurfaceTextureID(mContext, alloc);
310615e7cee03d1a53072b0369fa9f247811ac56845Jason Sams    }
311fe1d5ffd1b6c4977a9f301997d2ad90e5b049a3bJason Sams    native void rsnAllocationGetSurfaceTextureID2(int con, int alloc, SurfaceTexture st);
312fe1d5ffd1b6c4977a9f301997d2ad90e5b049a3bJason Sams    synchronized void nAllocationGetSurfaceTextureID2(int alloc, SurfaceTexture st) {
313fe1d5ffd1b6c4977a9f301997d2ad90e5b049a3bJason Sams        validate();
314fe1d5ffd1b6c4977a9f301997d2ad90e5b049a3bJason Sams        rsnAllocationGetSurfaceTextureID2(mContext, alloc, st);
315fe1d5ffd1b6c4977a9f301997d2ad90e5b049a3bJason Sams    }
316fb9aa9f3ef11878caaf6fcfb5ea49ffb9f7abf33Jason Sams    native void rsnAllocationSetSurface(int con, int alloc, Surface sur);
317fb9aa9f3ef11878caaf6fcfb5ea49ffb9f7abf33Jason Sams    synchronized void nAllocationSetSurface(int alloc, Surface sur) {
318163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams        validate();
319fb9aa9f3ef11878caaf6fcfb5ea49ffb9f7abf33Jason Sams        rsnAllocationSetSurface(mContext, alloc, sur);
320163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams    }
321163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams    native void rsnAllocationIoSend(int con, int alloc);
322163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams    synchronized void nAllocationIoSend(int alloc) {
323163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams        validate();
324163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams        rsnAllocationIoSend(mContext, alloc);
325163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams    }
326163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams    native void rsnAllocationIoReceive(int con, int alloc);
327163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams    synchronized void nAllocationIoReceive(int alloc) {
328163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams        validate();
329163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams        rsnAllocationIoReceive(mContext, alloc);
330163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams    }
331163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams
332615e7cee03d1a53072b0369fa9f247811ac56845Jason Sams
333f7086090cfc8d97b5bd3b4d7801a27af11f7c207Jason Sams    native void rsnAllocationGenerateMipmaps(int con, int alloc);
334f7086090cfc8d97b5bd3b4d7801a27af11f7c207Jason Sams    synchronized void nAllocationGenerateMipmaps(int alloc) {
335d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
336f7086090cfc8d97b5bd3b4d7801a27af11f7c207Jason Sams        rsnAllocationGenerateMipmaps(mContext, alloc);
337f7086090cfc8d97b5bd3b4d7801a27af11f7c207Jason Sams    }
3384ef6650bd05a39a09958ea1db92f120ea4949cb1Jason Sams    native void  rsnAllocationCopyFromBitmap(int con, int alloc, Bitmap bmp);
3394ef6650bd05a39a09958ea1db92f120ea4949cb1Jason Sams    synchronized void nAllocationCopyFromBitmap(int alloc, Bitmap bmp) {
340d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
3414ef6650bd05a39a09958ea1db92f120ea4949cb1Jason Sams        rsnAllocationCopyFromBitmap(mContext, alloc, bmp);
3422e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3432e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
3442e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
34549a05d7b82956009f03acbb92a064eed054eb031Jason Sams    native void rsnAllocationData1D(int con, int id, int off, int mip, int count, int[] d, int sizeBytes);
34649a05d7b82956009f03acbb92a064eed054eb031Jason Sams    synchronized void nAllocationData1D(int id, int off, int mip, int count, int[] d, int sizeBytes) {
347d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
34849a05d7b82956009f03acbb92a064eed054eb031Jason Sams        rsnAllocationData1D(mContext, id, off, mip, count, d, sizeBytes);
3492e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
35049a05d7b82956009f03acbb92a064eed054eb031Jason Sams    native void rsnAllocationData1D(int con, int id, int off, int mip, int count, short[] d, int sizeBytes);
35149a05d7b82956009f03acbb92a064eed054eb031Jason Sams    synchronized void nAllocationData1D(int id, int off, int mip, int count, short[] d, int sizeBytes) {
352d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
35349a05d7b82956009f03acbb92a064eed054eb031Jason Sams        rsnAllocationData1D(mContext, id, off, mip, count, d, sizeBytes);
3542e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
35549a05d7b82956009f03acbb92a064eed054eb031Jason Sams    native void rsnAllocationData1D(int con, int id, int off, int mip, int count, byte[] d, int sizeBytes);
35649a05d7b82956009f03acbb92a064eed054eb031Jason Sams    synchronized void nAllocationData1D(int id, int off, int mip, int count, byte[] d, int sizeBytes) {
357d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
35849a05d7b82956009f03acbb92a064eed054eb031Jason Sams        rsnAllocationData1D(mContext, id, off, mip, count, d, sizeBytes);
3592e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
36049a05d7b82956009f03acbb92a064eed054eb031Jason Sams    native void rsnAllocationData1D(int con, int id, int off, int mip, int count, float[] d, int sizeBytes);
36149a05d7b82956009f03acbb92a064eed054eb031Jason Sams    synchronized void nAllocationData1D(int id, int off, int mip, int count, float[] d, int sizeBytes) {
362d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
36349a05d7b82956009f03acbb92a064eed054eb031Jason Sams        rsnAllocationData1D(mContext, id, off, mip, count, d, sizeBytes);
36449bdaf0293408159df18a1d8540360f9623c40f7Jason Sams    }
36549a05d7b82956009f03acbb92a064eed054eb031Jason Sams
36649a05d7b82956009f03acbb92a064eed054eb031Jason Sams    native void rsnAllocationElementData1D(int con, int id, int xoff, int mip, int compIdx, byte[] d, int sizeBytes);
36749a05d7b82956009f03acbb92a064eed054eb031Jason Sams    synchronized void nAllocationElementData1D(int id, int xoff, int mip, int compIdx, byte[] d, int sizeBytes) {
368d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
36949a05d7b82956009f03acbb92a064eed054eb031Jason Sams        rsnAllocationElementData1D(mContext, id, xoff, mip, compIdx, d, sizeBytes);
3702e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3712e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
372304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk    native void rsnAllocationData2D(int con,
373304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                                    int dstAlloc, int dstXoff, int dstYoff,
374304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                                    int dstMip, int dstFace,
375304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                                    int width, int height,
376304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                                    int srcAlloc, int srcXoff, int srcYoff,
377304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                                    int srcMip, int srcFace);
378304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk    synchronized void nAllocationData2D(int dstAlloc, int dstXoff, int dstYoff,
379304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                                        int dstMip, int dstFace,
380304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                                        int width, int height,
381304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                                        int srcAlloc, int srcXoff, int srcYoff,
382304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                                        int srcMip, int srcFace) {
383304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk        validate();
384304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk        rsnAllocationData2D(mContext,
385304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                            dstAlloc, dstXoff, dstYoff,
386304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                            dstMip, dstFace,
387304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                            width, height,
388304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                            srcAlloc, srcXoff, srcYoff,
389304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                            srcMip, srcFace);
390304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk    }
391304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk
392fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    native void rsnAllocationData2D(int con, int id, int xoff, int yoff, int mip, int face, int w, int h, byte[] d, int sizeBytes);
393fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    synchronized void nAllocationData2D(int id, int xoff, int yoff, int mip, int face, int w, int h, byte[] d, int sizeBytes) {
394d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
395fa445b9353972735d8d65e8a936786b1afe9886dJason Sams        rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes);
396fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    }
397fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    native void rsnAllocationData2D(int con, int id, int xoff, int yoff, int mip, int face, int w, int h, short[] d, int sizeBytes);
398fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    synchronized void nAllocationData2D(int id, int xoff, int yoff, int mip, int face, int w, int h, short[] d, int sizeBytes) {
399d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
400fa445b9353972735d8d65e8a936786b1afe9886dJason Sams        rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes);
401fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    }
40249a05d7b82956009f03acbb92a064eed054eb031Jason Sams    native void rsnAllocationData2D(int con, int id, int xoff, int yoff, int mip, int face, int w, int h, int[] d, int sizeBytes);
40349a05d7b82956009f03acbb92a064eed054eb031Jason Sams    synchronized void nAllocationData2D(int id, int xoff, int yoff, int mip, int face, int w, int h, int[] d, int sizeBytes) {
404d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
40549a05d7b82956009f03acbb92a064eed054eb031Jason Sams        rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes);
4062e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
40749a05d7b82956009f03acbb92a064eed054eb031Jason Sams    native void rsnAllocationData2D(int con, int id, int xoff, int yoff, int mip, int face, int w, int h, float[] d, int sizeBytes);
40849a05d7b82956009f03acbb92a064eed054eb031Jason Sams    synchronized void nAllocationData2D(int id, int xoff, int yoff, int mip, int face, int w, int h, float[] d, int sizeBytes) {
409d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
41049a05d7b82956009f03acbb92a064eed054eb031Jason Sams        rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes);
4112e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
412fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    native void rsnAllocationData2D(int con, int id, int xoff, int yoff, int mip, int face, Bitmap b);
413fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    synchronized void nAllocationData2D(int id, int xoff, int yoff, int mip, int face, Bitmap b) {
414d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
415fa445b9353972735d8d65e8a936786b1afe9886dJason Sams        rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, b);
416fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    }
41749a05d7b82956009f03acbb92a064eed054eb031Jason Sams
418fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    native void rsnAllocationRead(int con, int id, byte[] d);
419fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    synchronized void nAllocationRead(int id, byte[] d) {
420d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
421fa445b9353972735d8d65e8a936786b1afe9886dJason Sams        rsnAllocationRead(mContext, id, d);
422fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    }
423fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    native void rsnAllocationRead(int con, int id, short[] d);
424fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    synchronized void nAllocationRead(int id, short[] d) {
425d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
426fa445b9353972735d8d65e8a936786b1afe9886dJason Sams        rsnAllocationRead(mContext, id, d);
427fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    }
4282e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAllocationRead(int con, int id, int[] d);
4292e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAllocationRead(int id, int[] d) {
430d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
4312e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAllocationRead(mContext, id, d);
4322e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4332e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAllocationRead(int con, int id, float[] d);
4342e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAllocationRead(int id, float[] d) {
435d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
4362e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAllocationRead(mContext, id, d);
4372e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4382e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnAllocationGetType(int con, int id);
4392e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nAllocationGetType(int id) {
440d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
4412e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnAllocationGetType(mContext, id);
4422e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4432e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
4445edc608a0749ed4b7074b5c1243043eb722c3c31Jason Sams    native void rsnAllocationResize1D(int con, int id, int dimX);
4455edc608a0749ed4b7074b5c1243043eb722c3c31Jason Sams    synchronized void nAllocationResize1D(int id, int dimX) {
446d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
4475edc608a0749ed4b7074b5c1243043eb722c3c31Jason Sams        rsnAllocationResize1D(mContext, id, dimX);
4485edc608a0749ed4b7074b5c1243043eb722c3c31Jason Sams    }
4495edc608a0749ed4b7074b5c1243043eb722c3c31Jason Sams    native void rsnAllocationResize2D(int con, int id, int dimX, int dimY);
4505edc608a0749ed4b7074b5c1243043eb722c3c31Jason Sams    synchronized void nAllocationResize2D(int id, int dimX, int dimY) {
451d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
4525edc608a0749ed4b7074b5c1243043eb722c3c31Jason Sams        rsnAllocationResize2D(mContext, id, dimX, dimY);
4535edc608a0749ed4b7074b5c1243043eb722c3c31Jason Sams    }
4545edc608a0749ed4b7074b5c1243043eb722c3c31Jason Sams
4552e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnFileA3DCreateFromAssetStream(int con, int assetStream);
4562e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nFileA3DCreateFromAssetStream(int assetStream) {
457d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
4582e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnFileA3DCreateFromAssetStream(mContext, assetStream);
4592e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
460b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    native int  rsnFileA3DCreateFromFile(int con, String path);
461b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    synchronized int nFileA3DCreateFromFile(String path) {
462d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
463b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk        return rsnFileA3DCreateFromFile(mContext, path);
464b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    }
465b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    native int  rsnFileA3DCreateFromAsset(int con, AssetManager mgr, String path);
466b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    synchronized int nFileA3DCreateFromAsset(AssetManager mgr, String path) {
467d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
468b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk        return rsnFileA3DCreateFromAsset(mContext, mgr, path);
469b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    }
4702e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnFileA3DGetNumIndexEntries(int con, int fileA3D);
4712e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nFileA3DGetNumIndexEntries(int fileA3D) {
472d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
4732e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnFileA3DGetNumIndexEntries(mContext, fileA3D);
4742e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4752e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnFileA3DGetIndexEntries(int con, int fileA3D, int numEntries, int[] IDs, String[] names);
4762e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nFileA3DGetIndexEntries(int fileA3D, int numEntries, int[] IDs, String[] names) {
477d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
4782e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnFileA3DGetIndexEntries(mContext, fileA3D, numEntries, IDs, names);
4792e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4802e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnFileA3DGetEntryByIndex(int con, int fileA3D, int index);
4812e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nFileA3DGetEntryByIndex(int fileA3D, int index) {
482d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
4832e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnFileA3DGetEntryByIndex(mContext, fileA3D, index);
4842e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4852e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
486e27cdeeecba5b445e307d653d9cb7da007adfac3Alex Sakhartchouk    native int  rsnFontCreateFromFile(int con, String fileName, float size, int dpi);
487e27cdeeecba5b445e307d653d9cb7da007adfac3Alex Sakhartchouk    synchronized int nFontCreateFromFile(String fileName, float size, int dpi) {
488d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
4892e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnFontCreateFromFile(mContext, fileName, size, dpi);
4902e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
491b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    native int  rsnFontCreateFromAssetStream(int con, String name, float size, int dpi, int assetStream);
492b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    synchronized int nFontCreateFromAssetStream(String name, float size, int dpi, int assetStream) {
493d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
494b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk        return rsnFontCreateFromAssetStream(mContext, name, size, dpi, assetStream);
495b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    }
496b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    native int  rsnFontCreateFromAsset(int con, AssetManager mgr, String path, float size, int dpi);
497b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    synchronized int nFontCreateFromAsset(AssetManager mgr, String path, float size, int dpi) {
498d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
499b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk        return rsnFontCreateFromAsset(mContext, mgr, path, size, dpi);
500b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    }
5012e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
5022e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
5032e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnScriptBindAllocation(int con, int script, int alloc, int slot);
5042e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nScriptBindAllocation(int script, int alloc, int slot) {
505d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
5062e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnScriptBindAllocation(mContext, script, alloc, slot);
5072e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
5082e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnScriptSetTimeZone(int con, int script, byte[] timeZone);
5092e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nScriptSetTimeZone(int script, byte[] timeZone) {
510d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
5112e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnScriptSetTimeZone(mContext, script, timeZone);
5122e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
5132e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnScriptInvoke(int con, int id, int slot);
5142e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nScriptInvoke(int id, int slot) {
515d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
5162e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnScriptInvoke(mContext, id, slot);
5172e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
5186e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams    native void rsnScriptForEach(int con, int id, int slot, int ain, int aout, byte[] params);
5196e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams    native void rsnScriptForEach(int con, int id, int slot, int ain, int aout);
520eb8c29cb7ece3f4b7ad18e5393b07fa7418a541cTim Murray    native void rsnScriptForEachClipped(int con, int id, int slot, int ain, int aout, byte[] params,
521eb8c29cb7ece3f4b7ad18e5393b07fa7418a541cTim Murray                                        int xstart, int xend, int ystart, int yend, int zstart, int zend);
5226e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams    synchronized void nScriptForEach(int id, int slot, int ain, int aout, byte[] params) {
5236e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams        validate();
5246e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams        if (params == null) {
5256e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams            rsnScriptForEach(mContext, id, slot, ain, aout);
5266e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams        } else {
5276e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams            rsnScriptForEach(mContext, id, slot, ain, aout, params);
5286e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams        }
5296e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams    }
530eb8c29cb7ece3f4b7ad18e5393b07fa7418a541cTim Murray
531eb8c29cb7ece3f4b7ad18e5393b07fa7418a541cTim Murray    synchronized void nScriptForEachClipped(int id, int slot, int ain, int aout, byte[] params,
532eb8c29cb7ece3f4b7ad18e5393b07fa7418a541cTim Murray                                            int xstart, int xend, int ystart, int yend, int zstart, int zend) {
533eb8c29cb7ece3f4b7ad18e5393b07fa7418a541cTim Murray        validate();
534eb8c29cb7ece3f4b7ad18e5393b07fa7418a541cTim Murray        rsnScriptForEachClipped(mContext, id, slot, ain, aout, params, xstart, xend, ystart, yend, zstart, zend);
535eb8c29cb7ece3f4b7ad18e5393b07fa7418a541cTim Murray    }
536eb8c29cb7ece3f4b7ad18e5393b07fa7418a541cTim Murray
5372e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnScriptInvokeV(int con, int id, int slot, byte[] params);
5382e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nScriptInvokeV(int id, int slot, byte[] params) {
539d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
5402e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnScriptInvokeV(mContext, id, slot, params);
5412e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
5422e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnScriptSetVarI(int con, int id, int slot, int val);
5432e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nScriptSetVarI(int id, int slot, int val) {
544d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
5452e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnScriptSetVarI(mContext, id, slot, val);
5462e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
547031ec58cfc7a20927302a5300eba3f5fc1709b50Stephen Hines    native void rsnScriptSetVarJ(int con, int id, int slot, long val);
548031ec58cfc7a20927302a5300eba3f5fc1709b50Stephen Hines    synchronized void nScriptSetVarJ(int id, int slot, long val) {
549d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
550031ec58cfc7a20927302a5300eba3f5fc1709b50Stephen Hines        rsnScriptSetVarJ(mContext, id, slot, val);
551031ec58cfc7a20927302a5300eba3f5fc1709b50Stephen Hines    }
5522e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnScriptSetVarF(int con, int id, int slot, float val);
5532e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nScriptSetVarF(int id, int slot, float val) {
554d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
5552e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnScriptSetVarF(mContext, id, slot, val);
5562e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
557ca54ec302f5bddd1674ea1f36cd3b7c540b2fbcaStephen Hines    native void rsnScriptSetVarD(int con, int id, int slot, double val);
558ca54ec302f5bddd1674ea1f36cd3b7c540b2fbcaStephen Hines    synchronized void nScriptSetVarD(int id, int slot, double val) {
559d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
560ca54ec302f5bddd1674ea1f36cd3b7c540b2fbcaStephen Hines        rsnScriptSetVarD(mContext, id, slot, val);
561ca54ec302f5bddd1674ea1f36cd3b7c540b2fbcaStephen Hines    }
5622e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnScriptSetVarV(int con, int id, int slot, byte[] val);
5632e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nScriptSetVarV(int id, int slot, byte[] val) {
564d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
5652e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnScriptSetVarV(mContext, id, slot, val);
5662e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
567adeb809201fcb77ba2b76a814ae4cdc9dacb326bStephen Hines    native void rsnScriptSetVarVE(int con, int id, int slot, byte[] val,
568adeb809201fcb77ba2b76a814ae4cdc9dacb326bStephen Hines                                  int e, int[] dims);
569adeb809201fcb77ba2b76a814ae4cdc9dacb326bStephen Hines    synchronized void nScriptSetVarVE(int id, int slot, byte[] val,
570adeb809201fcb77ba2b76a814ae4cdc9dacb326bStephen Hines                                      int e, int[] dims) {
571adeb809201fcb77ba2b76a814ae4cdc9dacb326bStephen Hines        validate();
572adeb809201fcb77ba2b76a814ae4cdc9dacb326bStephen Hines        rsnScriptSetVarVE(mContext, id, slot, val, e, dims);
573adeb809201fcb77ba2b76a814ae4cdc9dacb326bStephen Hines    }
5746f4cf0b8885403ead157ae00fd43cf1282331c23Jason Sams    native void rsnScriptSetVarObj(int con, int id, int slot, int val);
5756f4cf0b8885403ead157ae00fd43cf1282331c23Jason Sams    synchronized void nScriptSetVarObj(int id, int slot, int val) {
576d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
5776f4cf0b8885403ead157ae00fd43cf1282331c23Jason Sams        rsnScriptSetVarObj(mContext, id, slot, val);
5786f4cf0b8885403ead157ae00fd43cf1282331c23Jason Sams    }
5792e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
580e4a06c5fc738bf219f2a495e12a637b2d0871651Jason Sams    native int  rsnScriptCCreate(int con, String resName, String cacheDir,
581e4a06c5fc738bf219f2a495e12a637b2d0871651Jason Sams                                 byte[] script, int length);
582e4a06c5fc738bf219f2a495e12a637b2d0871651Jason Sams    synchronized int nScriptCCreate(String resName, String cacheDir, byte[] script, int length) {
583d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
584e4a06c5fc738bf219f2a495e12a637b2d0871651Jason Sams        return rsnScriptCCreate(mContext, resName, cacheDir, script, length);
5852e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
5862e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
5876ab97682fd444586ee135912a4210417a1c8781bJason Sams    native int  rsnScriptIntrinsicCreate(int con, int id, int eid);
5886ab97682fd444586ee135912a4210417a1c8781bJason Sams    synchronized int nScriptIntrinsicCreate(int id, int eid) {
5896ab97682fd444586ee135912a4210417a1c8781bJason Sams        validate();
5906ab97682fd444586ee135912a4210417a1c8781bJason Sams        return rsnScriptIntrinsicCreate(mContext, id, eid);
5916ab97682fd444586ee135912a4210417a1c8781bJason Sams    }
5926ab97682fd444586ee135912a4210417a1c8781bJason Sams
59308a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    native int  rsnScriptKernelIDCreate(int con, int sid, int slot, int sig);
59408a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    synchronized int nScriptKernelIDCreate(int sid, int slot, int sig) {
59508a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams        validate();
59608a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams        return rsnScriptKernelIDCreate(mContext, sid, slot, sig);
59708a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    }
59808a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams
59908a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    native int  rsnScriptFieldIDCreate(int con, int sid, int slot);
60008a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    synchronized int nScriptFieldIDCreate(int sid, int slot) {
60108a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams        validate();
60208a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams        return rsnScriptFieldIDCreate(mContext, sid, slot);
60308a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    }
60408a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams
60508a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    native int  rsnScriptGroupCreate(int con, int[] kernels, int[] src, int[] dstk, int[] dstf, int[] types);
60608a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    synchronized int nScriptGroupCreate(int[] kernels, int[] src, int[] dstk, int[] dstf, int[] types) {
60708a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams        validate();
60808a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams        return rsnScriptGroupCreate(mContext, kernels, src, dstk, dstf, types);
60908a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    }
61008a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams
61108a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    native void rsnScriptGroupSetInput(int con, int group, int kernel, int alloc);
61208a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    synchronized void nScriptGroupSetInput(int group, int kernel, int alloc) {
61308a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams        validate();
61408a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams        rsnScriptGroupSetInput(mContext, group, kernel, alloc);
61508a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    }
61608a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams
61708a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    native void rsnScriptGroupSetOutput(int con, int group, int kernel, int alloc);
61808a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    synchronized void nScriptGroupSetOutput(int group, int kernel, int alloc) {
61908a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams        validate();
62008a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams        rsnScriptGroupSetOutput(mContext, group, kernel, alloc);
62108a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    }
62208a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams
62308a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    native void rsnScriptGroupExecute(int con, int group);
62408a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    synchronized void nScriptGroupExecute(int group) {
62508a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams        validate();
62608a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams        rsnScriptGroupExecute(mContext, group);
62708a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    }
62808a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams
629a89094aa3bc059c6e03b20b4c5b1ede4582f3da9Alex Sakhartchouk    native int  rsnSamplerCreate(int con, int magFilter, int minFilter,
630a89094aa3bc059c6e03b20b4c5b1ede4582f3da9Alex Sakhartchouk                                 int wrapS, int wrapT, int wrapR, float aniso);
631a89094aa3bc059c6e03b20b4c5b1ede4582f3da9Alex Sakhartchouk    synchronized int nSamplerCreate(int magFilter, int minFilter,
632a89094aa3bc059c6e03b20b4c5b1ede4582f3da9Alex Sakhartchouk                                 int wrapS, int wrapT, int wrapR, float aniso) {
633d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
634a89094aa3bc059c6e03b20b4c5b1ede4582f3da9Alex Sakhartchouk        return rsnSamplerCreate(mContext, magFilter, minFilter, wrapS, wrapT, wrapR, aniso);
6352e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
6362e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
637331bf9b14b1c5c1e88f5c4092b6e24fae887fb3bJason Sams    native int  rsnProgramStoreCreate(int con, boolean r, boolean g, boolean b, boolean a,
638331bf9b14b1c5c1e88f5c4092b6e24fae887fb3bJason Sams                                      boolean depthMask, boolean dither,
639331bf9b14b1c5c1e88f5c4092b6e24fae887fb3bJason Sams                                      int srcMode, int dstMode, int depthFunc);
640331bf9b14b1c5c1e88f5c4092b6e24fae887fb3bJason Sams    synchronized int nProgramStoreCreate(boolean r, boolean g, boolean b, boolean a,
641331bf9b14b1c5c1e88f5c4092b6e24fae887fb3bJason Sams                                         boolean depthMask, boolean dither,
642331bf9b14b1c5c1e88f5c4092b6e24fae887fb3bJason Sams                                         int srcMode, int dstMode, int depthFunc) {
643d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
644bd184c55850997a5c5e285357998dadbe95b7b5dJason Sams        return rsnProgramStoreCreate(mContext, r, g, b, a, depthMask, dither, srcMode,
645bd184c55850997a5c5e285357998dadbe95b7b5dJason Sams                                     dstMode, depthFunc);
6462e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
6472e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
64894aaed38467c71a6c804f0e18b41346a4013c25bJason Sams    native int  rsnProgramRasterCreate(int con, boolean pointSprite, int cullMode);
64994aaed38467c71a6c804f0e18b41346a4013c25bJason Sams    synchronized int nProgramRasterCreate(boolean pointSprite, int cullMode) {
650d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
65194aaed38467c71a6c804f0e18b41346a4013c25bJason Sams        return rsnProgramRasterCreate(mContext, pointSprite, cullMode);
6522e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
6532e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
6542e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnProgramBindConstants(int con, int pv, int slot, int mID);
6552e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nProgramBindConstants(int pv, int slot, int mID) {
656d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
6572e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnProgramBindConstants(mContext, pv, slot, mID);
6582e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
6592e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnProgramBindTexture(int con, int vpf, int slot, int a);
6602e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nProgramBindTexture(int vpf, int slot, int a) {
661d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
6622e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnProgramBindTexture(mContext, vpf, slot, a);
6632e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
6642e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnProgramBindSampler(int con, int vpf, int slot, int s);
6652e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nProgramBindSampler(int vpf, int slot, int s) {
666d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
6672e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnProgramBindSampler(mContext, vpf, slot, s);
6682e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
6692123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk    native int  rsnProgramFragmentCreate(int con, String shader, String[] texNames, int[] params);
6702123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk    synchronized int nProgramFragmentCreate(String shader, String[] texNames, int[] params) {
671d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
6722123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk        return rsnProgramFragmentCreate(mContext, shader, texNames, params);
6732e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
6742123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk    native int  rsnProgramVertexCreate(int con, String shader, String[] texNames, int[] params);
6752123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk    synchronized int nProgramVertexCreate(String shader, String[] texNames, int[] params) {
676d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
6772123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk        return rsnProgramVertexCreate(mContext, shader, texNames, params);
6782e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
6792e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
68025999a08a6652ff5d7d0973f279f1e92e04b3506Alex Sakhartchouk    native int  rsnMeshCreate(int con, int[] vtx, int[] idx, int[] prim);
68125999a08a6652ff5d7d0973f279f1e92e04b3506Alex Sakhartchouk    synchronized int nMeshCreate(int[] vtx, int[] idx, int[] prim) {
682d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
68325999a08a6652ff5d7d0973f279f1e92e04b3506Alex Sakhartchouk        return rsnMeshCreate(mContext, vtx, idx, prim);
6849d71e2180062931416092f26276a07e55b318f62Alex Sakhartchouk    }
6852e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnMeshGetVertexBufferCount(int con, int id);
6862e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nMeshGetVertexBufferCount(int id) {
687d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
6882e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnMeshGetVertexBufferCount(mContext, id);
6892e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
6902e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnMeshGetIndexCount(int con, int id);
6912e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nMeshGetIndexCount(int id) {
692d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
6932e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnMeshGetIndexCount(mContext, id);
6942e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
6952e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnMeshGetVertices(int con, int id, int[] vtxIds, int vtxIdCount);
6962e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nMeshGetVertices(int id, int[] vtxIds, int vtxIdCount) {
697d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
6982e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnMeshGetVertices(mContext, id, vtxIds, vtxIdCount);
6992e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
7002e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnMeshGetIndices(int con, int id, int[] idxIds, int[] primitives, int vtxIdCount);
7012e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nMeshGetIndices(int id, int[] idxIds, int[] primitives, int vtxIdCount) {
702d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
7032e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnMeshGetIndices(mContext, id, idxIds, primitives, vtxIdCount);
7042e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
7052e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
706f15ed0124ea7f7f87e4188a1dd15cc4917a62ee9Jason Sams    native int  rsnPathCreate(int con, int prim, boolean isStatic, int vtx, int loop, float q);
707f15ed0124ea7f7f87e4188a1dd15cc4917a62ee9Jason Sams    synchronized int nPathCreate(int prim, boolean isStatic, int vtx, int loop, float q) {
708f15ed0124ea7f7f87e4188a1dd15cc4917a62ee9Jason Sams        validate();
709f15ed0124ea7f7f87e4188a1dd15cc4917a62ee9Jason Sams        return rsnPathCreate(mContext, prim, isStatic, vtx, loop, q);
710f15ed0124ea7f7f87e4188a1dd15cc4917a62ee9Jason Sams    }
71160aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
712bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    int     mDev;
713bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    int     mContext;
714650a3eb7d621dc8e81573142a4498bbd07bcde27Romain Guy    @SuppressWarnings({"FieldCanBeLocal"})
715bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    MessageThread mMessageThread;
71660aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
7178cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_U8;
7188cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_I8;
7198cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_U16;
7208cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_I16;
7218cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_U32;
7228cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_I32;
72352d836332f6aae74ed97fda1b53681f36710af64Stephen Hines    Element mElement_U64;
724ef1dac28d3bf98bd61cd9874fb3ccab42105e9b6Stephen Hines    Element mElement_I64;
7258cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_F32;
72602f41705199336f808ece50d81585450e7f8f61fStephen Hines    Element mElement_F64;
727f110d4b787b91dabe968a812e76e5c1f8d953487Jason Sams    Element mElement_BOOLEAN;
7288cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams
7298cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_ELEMENT;
7308cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_TYPE;
7318cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_ALLOCATION;
7328cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_SAMPLER;
7338cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_SCRIPT;
7348cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_MESH;
7358cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_PROGRAM_FRAGMENT;
7368cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_PROGRAM_VERTEX;
7378cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_PROGRAM_RASTER;
7388cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_PROGRAM_STORE;
7393a2914132146f340511425d7f78540098606b512Stephen Hines    Element mElement_FONT;
740a70f416c9cf2fc6cc5e132c1d656ce07441d6b82Jason Sams
7413c0dfbab807a459622aeade4940daddf482dec66Jason Sams    Element mElement_A_8;
7423c0dfbab807a459622aeade4940daddf482dec66Jason Sams    Element mElement_RGB_565;
7433c0dfbab807a459622aeade4940daddf482dec66Jason Sams    Element mElement_RGB_888;
7443c0dfbab807a459622aeade4940daddf482dec66Jason Sams    Element mElement_RGBA_5551;
7453c0dfbab807a459622aeade4940daddf482dec66Jason Sams    Element mElement_RGBA_4444;
7463c0dfbab807a459622aeade4940daddf482dec66Jason Sams    Element mElement_RGBA_8888;
7473c0dfbab807a459622aeade4940daddf482dec66Jason Sams
7488cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_FLOAT_2;
7498cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_FLOAT_3;
7508cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_FLOAT_4;
751836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines
752836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_DOUBLE_2;
753836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_DOUBLE_3;
754836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_DOUBLE_4;
755836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines
756836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_UCHAR_2;
757836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_UCHAR_3;
7588cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_UCHAR_4;
7597d787b4722eaeb79cab42c36060336e092b77b5fJason Sams
760836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_CHAR_2;
761836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_CHAR_3;
762836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_CHAR_4;
763836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines
764836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_USHORT_2;
765836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_USHORT_3;
766836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_USHORT_4;
767836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines
768836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_SHORT_2;
769836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_SHORT_3;
770836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_SHORT_4;
771836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines
772836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_UINT_2;
773836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_UINT_3;
774836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_UINT_4;
775836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines
776836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_INT_2;
777836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_INT_3;
778836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_INT_4;
779836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines
780836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_ULONG_2;
781836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_ULONG_3;
782836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_ULONG_4;
783836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines
784836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_LONG_2;
785836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_LONG_3;
786836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_LONG_4;
787836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines
7881d45c47975ab2a8cef6db5a8976276de31e1e8d0Jason Sams    Element mElement_MATRIX_4X4;
7891d45c47975ab2a8cef6db5a8976276de31e1e8d0Jason Sams    Element mElement_MATRIX_3X3;
7901d45c47975ab2a8cef6db5a8976276de31e1e8d0Jason Sams    Element mElement_MATRIX_2X2;
7911d45c47975ab2a8cef6db5a8976276de31e1e8d0Jason Sams
7924d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    Sampler mSampler_CLAMP_NEAREST;
7934d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    Sampler mSampler_CLAMP_LINEAR;
7944d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    Sampler mSampler_CLAMP_LINEAR_MIP_LINEAR;
7954d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    Sampler mSampler_WRAP_NEAREST;
7964d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    Sampler mSampler_WRAP_LINEAR;
7974d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    Sampler mSampler_WRAP_LINEAR_MIP_LINEAR;
7986b9b2caf2bf977508e223792bb5eba75091c232dTim Murray    Sampler mSampler_MIRRORED_REPEAT_NEAREST;
7996b9b2caf2bf977508e223792bb5eba75091c232dTim Murray    Sampler mSampler_MIRRORED_REPEAT_LINEAR;
8006b9b2caf2bf977508e223792bb5eba75091c232dTim Murray    Sampler mSampler_MIRRORED_REPEAT_LINEAR_MIP_LINEAR;
8014d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams
802d36f248eaf06c569010649902df653da1a9e2accAlex Sakhartchouk    ProgramStore mProgramStore_BLEND_NONE_DEPTH_TEST;
803d36f248eaf06c569010649902df653da1a9e2accAlex Sakhartchouk    ProgramStore mProgramStore_BLEND_NONE_DEPTH_NO_DEPTH;
804d36f248eaf06c569010649902df653da1a9e2accAlex Sakhartchouk    ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_TEST;
805d36f248eaf06c569010649902df653da1a9e2accAlex Sakhartchouk    ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_NO_DEPTH;
806d36f248eaf06c569010649902df653da1a9e2accAlex Sakhartchouk
807d36f248eaf06c569010649902df653da1a9e2accAlex Sakhartchouk    ProgramRaster mProgramRaster_CULL_BACK;
808d36f248eaf06c569010649902df653da1a9e2accAlex Sakhartchouk    ProgramRaster mProgramRaster_CULL_FRONT;
809d36f248eaf06c569010649902df653da1a9e2accAlex Sakhartchouk    ProgramRaster mProgramRaster_CULL_NONE;
81032e09b5891da0174f161d99e2d3ebe67d6efa39cAlex Sakhartchouk
81160aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich    ///////////////////////////////////////////////////////////////////////////////////
81243702d8925c54360ad5f9f66b0d35d61d59f6910Jack Palevich    //
81360aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
8149c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines    /**
81527676fe24be7444a174c15df476e49adc5335d03Jason Sams     * Base class application should derive from for handling RS messages
8168cecbb5293f73e3f63f2601dda68016762c58a0cStephen Hines     * coming from their scripts.  When a script calls sendToClient the data
81727676fe24be7444a174c15df476e49adc5335d03Jason Sams     * fields will be filled in and then the run method called by a message
81827676fe24be7444a174c15df476e49adc5335d03Jason Sams     * handling thread.  This will occur some time after sendToClient completes
81927676fe24be7444a174c15df476e49adc5335d03Jason Sams     * in the script.
82027676fe24be7444a174c15df476e49adc5335d03Jason Sams     *
82127676fe24be7444a174c15df476e49adc5335d03Jason Sams     */
822bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    public static class RSMessageHandler implements Runnable {
823516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        protected int[] mData;
824516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        protected int mID;
8251c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams        protected int mLength;
826516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        public void run() {
827516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        }
828516c31911578db8ce53529483c3ded918ac7dc6bJason Sams    }
8299c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines    /**
83027676fe24be7444a174c15df476e49adc5335d03Jason Sams     * If an application is expecting messages it should set this field to an
83127676fe24be7444a174c15df476e49adc5335d03Jason Sams     * instance of RSMessage.  This instance will receive all the user messages
83227676fe24be7444a174c15df476e49adc5335d03Jason Sams     * sent from sendToClient by scripts from this context.
83327676fe24be7444a174c15df476e49adc5335d03Jason Sams     *
83427676fe24be7444a174c15df476e49adc5335d03Jason Sams     */
835bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    RSMessageHandler mMessageCallback = null;
836bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams
837bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    public void setMessageHandler(RSMessageHandler msg) {
838bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams        mMessageCallback = msg;
839bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    }
840bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    public RSMessageHandler getMessageHandler() {
841bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams        return mMessageCallback;
842bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    }
843516c31911578db8ce53529483c3ded918ac7dc6bJason Sams
8449c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines    /**
845455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams     * @hide
846455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams     *
847455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams     * @param id
848455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams     * @param data
849455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams     */
850455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams    public void sendMessage(int id, int[] data) {
851455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams        nContextSendMessage(id, data);
852455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams    }
853455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams
854455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams    /**
85527676fe24be7444a174c15df476e49adc5335d03Jason Sams     * Runtime error base class.  An application should derive from this class
85627676fe24be7444a174c15df476e49adc5335d03Jason Sams     * if it wishes to install an error handler.  When errors occur at runtime
85727676fe24be7444a174c15df476e49adc5335d03Jason Sams     * the fields in this class will be filled and the run method called.
85827676fe24be7444a174c15df476e49adc5335d03Jason Sams     *
85927676fe24be7444a174c15df476e49adc5335d03Jason Sams     */
860bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    public static class RSErrorHandler implements Runnable {
8611c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams        protected String mErrorMessage;
8621c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams        protected int mErrorNum;
8631c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams        public void run() {
8641c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams        }
8651c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams    }
86627676fe24be7444a174c15df476e49adc5335d03Jason Sams
8679c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines    /**
86827676fe24be7444a174c15df476e49adc5335d03Jason Sams     * Application Error handler.  All runtime errors will be dispatched to the
86927676fe24be7444a174c15df476e49adc5335d03Jason Sams     * instance of RSAsyncError set here.  If this field is null a
87027676fe24be7444a174c15df476e49adc5335d03Jason Sams     * RSRuntimeException will instead be thrown with details about the error.
87127676fe24be7444a174c15df476e49adc5335d03Jason Sams     * This will cause program termaination.
87227676fe24be7444a174c15df476e49adc5335d03Jason Sams     *
87327676fe24be7444a174c15df476e49adc5335d03Jason Sams     */
874bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    RSErrorHandler mErrorCallback = null;
875bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams
876bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    public void setErrorHandler(RSErrorHandler msg) {
877bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams        mErrorCallback = msg;
878bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    }
879bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    public RSErrorHandler getErrorHandler() {
880bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams        return mErrorCallback;
881bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    }
8821c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams
8839c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines    /**
88427676fe24be7444a174c15df476e49adc5335d03Jason Sams     * RenderScript worker threads priority enumeration.  The default value is
88527676fe24be7444a174c15df476e49adc5335d03Jason Sams     * NORMAL.  Applications wishing to do background processing such as
88627676fe24be7444a174c15df476e49adc5335d03Jason Sams     * wallpapers should set their priority to LOW to avoid starving forground
88727676fe24be7444a174c15df476e49adc5335d03Jason Sams     * processes.
88827676fe24be7444a174c15df476e49adc5335d03Jason Sams     */
8897d787b4722eaeb79cab42c36060336e092b77b5fJason Sams    public enum Priority {
890260c77a4f741c3db76057cc4ea2ee54fe335ecf9Glenn Kasten        LOW (Process.THREAD_PRIORITY_BACKGROUND + (5 * Process.THREAD_PRIORITY_LESS_FAVORABLE)),
891260c77a4f741c3db76057cc4ea2ee54fe335ecf9Glenn Kasten        NORMAL (Process.THREAD_PRIORITY_DISPLAY);
8927d787b4722eaeb79cab42c36060336e092b77b5fJason Sams
8937d787b4722eaeb79cab42c36060336e092b77b5fJason Sams        int mID;
8947d787b4722eaeb79cab42c36060336e092b77b5fJason Sams        Priority(int id) {
8957d787b4722eaeb79cab42c36060336e092b77b5fJason Sams            mID = id;
8967d787b4722eaeb79cab42c36060336e092b77b5fJason Sams        }
8977d787b4722eaeb79cab42c36060336e092b77b5fJason Sams    }
8987d787b4722eaeb79cab42c36060336e092b77b5fJason Sams
899771bebb94054d06f97284379c93a2620613513c3Jason Sams    void validate() {
900771bebb94054d06f97284379c93a2620613513c3Jason Sams        if (mContext == 0) {
901c1d6210fb5cc558ccea95a59a2b33bb9015fc7deJason Sams            throw new RSInvalidStateException("Calling RS with no Context active.");
902771bebb94054d06f97284379c93a2620613513c3Jason Sams        }
903771bebb94054d06f97284379c93a2620613513c3Jason Sams    }
904771bebb94054d06f97284379c93a2620613513c3Jason Sams
90527676fe24be7444a174c15df476e49adc5335d03Jason Sams
9069c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines    /**
90727676fe24be7444a174c15df476e49adc5335d03Jason Sams     * Change the priority of the worker threads for this context.
90827676fe24be7444a174c15df476e49adc5335d03Jason Sams     *
90927676fe24be7444a174c15df476e49adc5335d03Jason Sams     * @param p New priority to be set.
91027676fe24be7444a174c15df476e49adc5335d03Jason Sams     */
911bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    public void setPriority(Priority p) {
9125dbfe93b3f15f3a837836d024958635fd8f9ad14Jason Sams        validate();
9137d787b4722eaeb79cab42c36060336e092b77b5fJason Sams        nContextSetPriority(p.mID);
9147d787b4722eaeb79cab42c36060336e092b77b5fJason Sams    }
9157d787b4722eaeb79cab42c36060336e092b77b5fJason Sams
916bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    static class MessageThread extends Thread {
917516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        RenderScript mRS;
918516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        boolean mRun = true;
919bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams        int[] mAuxData = new int[2];
9201c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams
921bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams        static final int RS_MESSAGE_TO_CLIENT_NONE = 0;
922bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams        static final int RS_MESSAGE_TO_CLIENT_EXCEPTION = 1;
923bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams        static final int RS_MESSAGE_TO_CLIENT_RESIZE = 2;
924bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams        static final int RS_MESSAGE_TO_CLIENT_ERROR = 3;
925bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams        static final int RS_MESSAGE_TO_CLIENT_USER = 4;
926516c31911578db8ce53529483c3ded918ac7dc6bJason Sams
927bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams        static final int RS_ERROR_FATAL_UNKNOWN = 0x1000;
928add9d9633205f76cc34f04368b8482c2c369ba63Jason Sams
929516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        MessageThread(RenderScript rs) {
930516c31911578db8ce53529483c3ded918ac7dc6bJason Sams            super("RSMessageThread");
931516c31911578db8ce53529483c3ded918ac7dc6bJason Sams            mRS = rs;
932516c31911578db8ce53529483c3ded918ac7dc6bJason Sams
933516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        }
934516c31911578db8ce53529483c3ded918ac7dc6bJason Sams
935516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        public void run() {
936516c31911578db8ce53529483c3ded918ac7dc6bJason Sams            // This function is a temporary solution.  The final solution will
937516c31911578db8ce53529483c3ded918ac7dc6bJason Sams            // used typed allocations where the message id is the type indicator.
938516c31911578db8ce53529483c3ded918ac7dc6bJason Sams            int[] rbuf = new int[16];
9392e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams            mRS.nContextInitToClient(mRS.mContext);
940516c31911578db8ce53529483c3ded918ac7dc6bJason Sams            while(mRun) {
9411d45c47975ab2a8cef6db5a8976276de31e1e8d0Jason Sams                rbuf[0] = 0;
942edbfabdb98a2974f973d6c042e6efd547dc02fc5Jason Sams                int msg = mRS.nContextPeekMessage(mRS.mContext, mAuxData);
943bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams                int size = mAuxData[1];
944bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams                int subID = mAuxData[0];
9451c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams
9461c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                if (msg == RS_MESSAGE_TO_CLIENT_USER) {
9471c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                    if ((size>>2) >= rbuf.length) {
9481c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                        rbuf = new int[(size + 3) >> 2];
9491c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                    }
950edbfabdb98a2974f973d6c042e6efd547dc02fc5Jason Sams                    if (mRS.nContextGetUserMessage(mRS.mContext, rbuf) !=
951edbfabdb98a2974f973d6c042e6efd547dc02fc5Jason Sams                        RS_MESSAGE_TO_CLIENT_USER) {
952edbfabdb98a2974f973d6c042e6efd547dc02fc5Jason Sams                        throw new RSDriverException("Error processing message from Renderscript.");
953edbfabdb98a2974f973d6c042e6efd547dc02fc5Jason Sams                    }
9541c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams
9551c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                    if(mRS.mMessageCallback != null) {
9561c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                        mRS.mMessageCallback.mData = rbuf;
9571c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                        mRS.mMessageCallback.mID = subID;
9581c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                        mRS.mMessageCallback.mLength = size;
9591c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                        mRS.mMessageCallback.run();
9601d45c47975ab2a8cef6db5a8976276de31e1e8d0Jason Sams                    } else {
9611c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                        throw new RSInvalidStateException("Received a message from the script with no message handler installed.");
962516c31911578db8ce53529483c3ded918ac7dc6bJason Sams                    }
963ab98bb6e8b95bef7415c1ad239be71f93322fbadStephen Hines                    continue;
964516c31911578db8ce53529483c3ded918ac7dc6bJason Sams                }
9651c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams
9661c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                if (msg == RS_MESSAGE_TO_CLIENT_ERROR) {
9671c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                    String e = mRS.nContextGetErrorMessage(mRS.mContext);
9681c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams
969add9d9633205f76cc34f04368b8482c2c369ba63Jason Sams                    if (subID >= RS_ERROR_FATAL_UNKNOWN) {
970add9d9633205f76cc34f04368b8482c2c369ba63Jason Sams                        throw new RSRuntimeException("Fatal error " + subID + ", details: " + e);
971add9d9633205f76cc34f04368b8482c2c369ba63Jason Sams                    }
972add9d9633205f76cc34f04368b8482c2c369ba63Jason Sams
9731c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                    if(mRS.mErrorCallback != null) {
9741c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                        mRS.mErrorCallback.mErrorMessage = e;
9751c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                        mRS.mErrorCallback.mErrorNum = subID;
9761c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                        mRS.mErrorCallback.run();
9771c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                    } else {
978a4b7bc97862e01d38b483524f1d1cf433d29e294Jason Sams                        android.util.Log.e(LOG_TAG, "non fatal RS error, " + e);
979be74bdd2349095f203ae0fddcc4816bfbd56bc5dStephen Hines                        // Do not throw here. In these cases, we do not have
980be74bdd2349095f203ae0fddcc4816bfbd56bc5dStephen Hines                        // a fatal error.
9811c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                    }
9821c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                    continue;
9831c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                }
9841c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams
9851c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                // 2: teardown.
9861c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                // But we want to avoid starving other threads during
9871c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                // teardown by yielding until the next line in the destructor
9881c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                // can execute to set mRun = false
9891c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                try {
9901c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                    sleep(1, 0);
9911c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                } catch(InterruptedException e) {
992516c31911578db8ce53529483c3ded918ac7dc6bJason Sams                }
993516c31911578db8ce53529483c3ded918ac7dc6bJason Sams            }
9943bc47d438171dce294e816366d53bc9eca772c5bJason Sams            Log.d(LOG_TAG, "MessageThread exiting.");
995516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        }
996516c31911578db8ce53529483c3ded918ac7dc6bJason Sams    }
997516c31911578db8ce53529483c3ded918ac7dc6bJason Sams
9986b32fab1dbfd8bc1cc176557fe0a7b2ebd4966bdShih-wei Liao    RenderScript(Context ctx) {
9991a4e1f3efd077f3a61038aedab84dc84c9c44d19Jason Sams        if (ctx != null) {
10001a4e1f3efd077f3a61038aedab84dc84c9c44d19Jason Sams            mApplicationContext = ctx.getApplicationContext();
10011a4e1f3efd077f3a61038aedab84dc84c9c44d19Jason Sams        }
100260aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich    }
100360aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
10049c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines    /**
10056b32fab1dbfd8bc1cc176557fe0a7b2ebd4966bdShih-wei Liao     * Gets the application context associated with the RenderScript context.
100627676fe24be7444a174c15df476e49adc5335d03Jason Sams     *
10076b32fab1dbfd8bc1cc176557fe0a7b2ebd4966bdShih-wei Liao     * @return The application context.
10086b32fab1dbfd8bc1cc176557fe0a7b2ebd4966bdShih-wei Liao     */
10096b32fab1dbfd8bc1cc176557fe0a7b2ebd4966bdShih-wei Liao    public final Context getApplicationContext() {
10106b32fab1dbfd8bc1cc176557fe0a7b2ebd4966bdShih-wei Liao        return mApplicationContext;
10116b32fab1dbfd8bc1cc176557fe0a7b2ebd4966bdShih-wei Liao    }
10126b32fab1dbfd8bc1cc176557fe0a7b2ebd4966bdShih-wei Liao
10139c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines    /**
10146b32fab1dbfd8bc1cc176557fe0a7b2ebd4966bdShih-wei Liao     * Create a basic RenderScript context.
101527676fe24be7444a174c15df476e49adc5335d03Jason Sams     *
10161a4e1f3efd077f3a61038aedab84dc84c9c44d19Jason Sams     * @hide
10176b32fab1dbfd8bc1cc176557fe0a7b2ebd4966bdShih-wei Liao     * @param ctx The context.
101827676fe24be7444a174c15df476e49adc5335d03Jason Sams     * @return RenderScript
101927676fe24be7444a174c15df476e49adc5335d03Jason Sams     */
10201a4e1f3efd077f3a61038aedab84dc84c9c44d19Jason Sams    public static RenderScript create(Context ctx, int sdkVersion) {
10216b32fab1dbfd8bc1cc176557fe0a7b2ebd4966bdShih-wei Liao        RenderScript rs = new RenderScript(ctx);
1022704ff64b099406bb328898a7443921f22dbffd6dJason Sams
1023704ff64b099406bb328898a7443921f22dbffd6dJason Sams        rs.mDev = rs.nDeviceCreate();
10244382467a80dd12c6362d57edca7f2367f7ae877cStephen Hines        rs.mContext = rs.nContextCreate(rs.mDev, 0, sdkVersion);
10252698536b3ff60bfee85e47e4a8d4b25fdfdf4db5Jason Sams        if (rs.mContext == 0) {
10262698536b3ff60bfee85e47e4a8d4b25fdfdf4db5Jason Sams            throw new RSDriverException("Failed to create RS context.");
10272698536b3ff60bfee85e47e4a8d4b25fdfdf4db5Jason Sams        }
1028704ff64b099406bb328898a7443921f22dbffd6dJason Sams        rs.mMessageThread = new MessageThread(rs);
1029704ff64b099406bb328898a7443921f22dbffd6dJason Sams        rs.mMessageThread.start();
1030704ff64b099406bb328898a7443921f22dbffd6dJason Sams        return rs;
1031efd9b6fb2e0f31b50db089352118e5daeb268879Jason Sams    }
1032efd9b6fb2e0f31b50db089352118e5daeb268879Jason Sams
10339c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines    /**
10341a4e1f3efd077f3a61038aedab84dc84c9c44d19Jason Sams     * Create a basic RenderScript context.
10351a4e1f3efd077f3a61038aedab84dc84c9c44d19Jason Sams     *
10361a4e1f3efd077f3a61038aedab84dc84c9c44d19Jason Sams     * @param ctx The context.
10371a4e1f3efd077f3a61038aedab84dc84c9c44d19Jason Sams     * @return RenderScript
10381a4e1f3efd077f3a61038aedab84dc84c9c44d19Jason Sams     */
10391a4e1f3efd077f3a61038aedab84dc84c9c44d19Jason Sams    public static RenderScript create(Context ctx) {
10401a4e1f3efd077f3a61038aedab84dc84c9c44d19Jason Sams        int v = ctx.getApplicationInfo().targetSdkVersion;
10411a4e1f3efd077f3a61038aedab84dc84c9c44d19Jason Sams        return create(ctx, v);
10421a4e1f3efd077f3a61038aedab84dc84c9c44d19Jason Sams    }
10431a4e1f3efd077f3a61038aedab84dc84c9c44d19Jason Sams
10449c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines    /**
104527676fe24be7444a174c15df476e49adc5335d03Jason Sams     * Print the currently available debugging information about the state of
104627676fe24be7444a174c15df476e49adc5335d03Jason Sams     * the RS context to the log.
104727676fe24be7444a174c15df476e49adc5335d03Jason Sams     *
104827676fe24be7444a174c15df476e49adc5335d03Jason Sams     */
1049bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    public void contextDump() {
10505dbfe93b3f15f3a837836d024958635fd8f9ad14Jason Sams        validate();
1051bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams        nContextDump(0);
1052715333b832fb448c32165c7d97d408a3fa43f7cbJason Sams    }
1053715333b832fb448c32165c7d97d408a3fa43f7cbJason Sams
10549c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines    /**
105527676fe24be7444a174c15df476e49adc5335d03Jason Sams     * Wait for any commands in the fifo between the java bindings and native to
105627676fe24be7444a174c15df476e49adc5335d03Jason Sams     * be processed.
105727676fe24be7444a174c15df476e49adc5335d03Jason Sams     *
105827676fe24be7444a174c15df476e49adc5335d03Jason Sams     */
105996ed4cfa62dd09aafb3f9da01e047661b4fe3c95Jason Sams    public void finish() {
106096ed4cfa62dd09aafb3f9da01e047661b4fe3c95Jason Sams        nContextFinish();
106196ed4cfa62dd09aafb3f9da01e047661b4fe3c95Jason Sams    }
106296ed4cfa62dd09aafb3f9da01e047661b4fe3c95Jason Sams
10639c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines    /**
106427676fe24be7444a174c15df476e49adc5335d03Jason Sams     * Destroy this renderscript context.  Once this function is called its no
106527676fe24be7444a174c15df476e49adc5335d03Jason Sams     * longer legal to use this or any objects created by this context.
106627676fe24be7444a174c15df476e49adc5335d03Jason Sams     *
106727676fe24be7444a174c15df476e49adc5335d03Jason Sams     */
1068f5b4596a383b6ab83f92edecfe054e80b555c2d0Jason Sams    public void destroy() {
10695dbfe93b3f15f3a837836d024958635fd8f9ad14Jason Sams        validate();
10702e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        nContextDeinitToClient(mContext);
1071516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        mMessageThread.mRun = false;
1072a8bf9429b29743b3489817feb21bde2416acc465Jason Sams        try {
1073a8bf9429b29743b3489817feb21bde2416acc465Jason Sams            mMessageThread.join();
1074a8bf9429b29743b3489817feb21bde2416acc465Jason Sams        } catch(InterruptedException e) {
1075a8bf9429b29743b3489817feb21bde2416acc465Jason Sams        }
1076516c31911578db8ce53529483c3ded918ac7dc6bJason Sams
10772e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        nContextDestroy();
1078f5b4596a383b6ab83f92edecfe054e80b555c2d0Jason Sams        mContext = 0;
1079f5b4596a383b6ab83f92edecfe054e80b555c2d0Jason Sams
1080f5b4596a383b6ab83f92edecfe054e80b555c2d0Jason Sams        nDeviceDestroy(mDev);
1081f5b4596a383b6ab83f92edecfe054e80b555c2d0Jason Sams        mDev = 0;
1082f5b4596a383b6ab83f92edecfe054e80b555c2d0Jason Sams    }
108302fb2cb531035779a25dbf9595e0628ea40585b0Jason Sams
1084a9e7a05b84470257637c97d65f6562aa832c66efJason Sams    boolean isAlive() {
1085a9e7a05b84470257637c97d65f6562aa832c66efJason Sams        return mContext != 0;
1086a9e7a05b84470257637c97d65f6562aa832c66efJason Sams    }
1087a9e7a05b84470257637c97d65f6562aa832c66efJason Sams
1088bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    int safeID(BaseObj o) {
10896b9dec00afec359f091ed353f371f08ff150278aJason Sams        if(o != null) {
1090e07694b24f7d12d72b084b6651356681ebd0efd6Jason Sams            return o.getID(this);
1091d8e4161f114331343b897cbacea927e7e60e7b17Jason Sams        }
10926b9dec00afec359f091ed353f371f08ff150278aJason Sams        return 0;
109360aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich    }
109460aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich}
1095