RenderScript.java revision 6d7a53cbddbffba30f7e9f82ced9c1ab46214f5a
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;
32e4d9a01bfc7451afff1ed399a5801c7aa2af2831Dan Morrillimport android.os.SystemProperties;
336d7a53cbddbffba30f7e9f82ced9c1ab46214f5aTim Murrayimport android.os.Trace;
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 {
486d7a53cbddbffba30f7e9f82ced9c1ab46214f5aTim Murray    static final long TRACE_TAG = Trace.TRACE_TAG_RS;
496d7a53cbddbffba30f7e9f82ced9c1ab46214f5aTim Murray
503bc47d438171dce294e816366d53bc9eca772c5bJason Sams    static final String LOG_TAG = "RenderScript_jni";
51bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    static final boolean DEBUG  = false;
52650a3eb7d621dc8e81573142a4498bbd07bcde27Romain Guy    @SuppressWarnings({"UnusedDeclaration", "deprecation"})
5343a17654cf4bfe7f1ec22bd8b7b32daccdf27c09Joe Onorato    static final boolean LOG_ENABLED = false;
5460aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
556b32fab1dbfd8bc1cc176557fe0a7b2ebd4966bdShih-wei Liao    private Context mApplicationContext;
5660aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
576b32fab1dbfd8bc1cc176557fe0a7b2ebd4966bdShih-wei Liao    /*
5860aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich     * We use a class initializer to allow the native code to cache some
5960aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich     * field offsets.
6060aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich     */
61e4d9a01bfc7451afff1ed399a5801c7aa2af2831Dan Morrill    @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"}) // TODO: now used locally; remove?
62bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    static boolean sInitialized;
63bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    native static void _nInit();
6460aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
65dba3ba5b5bf6026abceced921b1b0d231b0faefdJason Sams
6660aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich    static {
6760aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich        sInitialized = false;
68e4d9a01bfc7451afff1ed399a5801c7aa2af2831Dan Morrill        if (!SystemProperties.getBoolean("config.disable_renderscript", false)) {
69e4d9a01bfc7451afff1ed399a5801c7aa2af2831Dan Morrill            try {
70e4d9a01bfc7451afff1ed399a5801c7aa2af2831Dan Morrill                System.loadLibrary("rs_jni");
71e4d9a01bfc7451afff1ed399a5801c7aa2af2831Dan Morrill                _nInit();
72e4d9a01bfc7451afff1ed399a5801c7aa2af2831Dan Morrill                sInitialized = true;
73e4d9a01bfc7451afff1ed399a5801c7aa2af2831Dan Morrill            } catch (UnsatisfiedLinkError e) {
74e4d9a01bfc7451afff1ed399a5801c7aa2af2831Dan Morrill                Log.e(LOG_TAG, "Error loading RS jni library: " + e);
75e4d9a01bfc7451afff1ed399a5801c7aa2af2831Dan Morrill                throw new RSRuntimeException("Error loading RS jni library: " + e);
76e4d9a01bfc7451afff1ed399a5801c7aa2af2831Dan Morrill            }
7760aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich        }
7860aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich    }
7960aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
802e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    // Non-threadsafe functions.
8136e612a488511940b61f09803b270aa1c61b68e0Jason Sams    native int  nDeviceCreate();
8236e612a488511940b61f09803b270aa1c61b68e0Jason Sams    native void nDeviceDestroy(int dev);
83ebfb436a49673693b98469683451bd9ede797557Jason Sams    native void nDeviceSetConfig(int dev, int param, int value);
84edbfabdb98a2974f973d6c042e6efd547dc02fc5Jason Sams    native int nContextGetUserMessage(int con, int[] data);
851c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams    native String nContextGetErrorMessage(int con);
86edbfabdb98a2974f973d6c042e6efd547dc02fc5Jason Sams    native int  nContextPeekMessage(int con, int[] subID);
872e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void nContextInitToClient(int con);
882e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void nContextDeinitToClient(int con);
892e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
907d25a829d3da96fb6ac0d285aa1bfb2022271beeStephen Hines    static File mCacheDir;
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) {
100e4d9a01bfc7451afff1ed399a5801c7aa2af2831Dan Morrill        if (!sInitialized) {
101e4d9a01bfc7451afff1ed399a5801c7aa2af2831Dan Morrill            Log.e(LOG_TAG, "RenderScript.setupDiskCache() called when disabled");
102e4d9a01bfc7451afff1ed399a5801c7aa2af2831Dan Morrill            return;
103e4d9a01bfc7451afff1ed399a5801c7aa2af2831Dan Morrill        }
104e4d9a01bfc7451afff1ed399a5801c7aa2af2831Dan Morrill
1057d25a829d3da96fb6ac0d285aa1bfb2022271beeStephen Hines        // Defer creation of cache path to nScriptCCreate().
1067d25a829d3da96fb6ac0d285aa1bfb2022271beeStephen Hines        mCacheDir = cacheDir;
107a6f338ca5f0c8359d1952167858851dd025e47e2Jason Sams    }
108a6f338ca5f0c8359d1952167858851dd025e47e2Jason Sams
10902d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams    /**
11002d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams     * ContextType specifies the specific type of context to be created.
11102d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams     *
11202d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams     */
113add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams    public enum ContextType {
11402d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams        /**
11502d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams         * NORMAL context, this is the default and what shipping apps should
11602d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams         * use.
11702d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams         */
118add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams        NORMAL (0),
11902d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams
12002d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams        /**
12102d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams         * DEBUG context, perform extra runtime checks to validate the
12202d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams         * kernels and APIs are being used as intended.  Get and SetElementAt
12302d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams         * will be bounds checked in this mode.
12402d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams         */
125add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams        DEBUG (1),
12602d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams
12702d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams        /**
12802d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams         * PROFILE context, Intended to be used once the first time an
12902d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams         * application is run on a new device.  This mode allows the runtime to
13002d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams         * do additional testing and performance tuning.
13102d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams         */
132add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams        PROFILE (2);
133add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams
134add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams        int mID;
135add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams        ContextType(int id) {
136add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams            mID = id;
137add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams        }
138add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams    }
1392e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
14042028a87568c2b7b5ff3691df7c345bbc5802adeStephen Hines    ContextType mContextType;
14142028a87568c2b7b5ff3691df7c345bbc5802adeStephen Hines
1422e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    // Methods below are wrapped to protect the non-threadsafe
1432e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    // lockless fifo.
1444382467a80dd12c6362d57edca7f2367f7ae877cStephen Hines    native int  rsnContextCreateGL(int dev, int ver, int sdkVer,
14511c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams                 int colorMin, int colorPref,
14611c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams                 int alphaMin, int alphaPref,
14711c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams                 int depthMin, int depthPref,
14811c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams                 int stencilMin, int stencilPref,
1492c74ad9aae29cc64fece926f353825a7925792c2Alex Sakhartchouk                 int samplesMin, int samplesPref, float samplesQ, int dpi);
1504382467a80dd12c6362d57edca7f2367f7ae877cStephen Hines    synchronized int nContextCreateGL(int dev, int ver, int sdkVer,
15111c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams                 int colorMin, int colorPref,
15211c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams                 int alphaMin, int alphaPref,
15311c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams                 int depthMin, int depthPref,
15411c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams                 int stencilMin, int stencilPref,
1552c74ad9aae29cc64fece926f353825a7925792c2Alex Sakhartchouk                 int samplesMin, int samplesPref, float samplesQ, int dpi) {
1564382467a80dd12c6362d57edca7f2367f7ae877cStephen Hines        return rsnContextCreateGL(dev, ver, sdkVer, colorMin, colorPref,
15711c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams                                  alphaMin, alphaPref, depthMin, depthPref,
15811c8af9ded3a319635b4e91a639a616ec97fc7e3Jason Sams                                  stencilMin, stencilPref,
1592c74ad9aae29cc64fece926f353825a7925792c2Alex Sakhartchouk                                  samplesMin, samplesPref, samplesQ, dpi);
1602e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
161add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams    native int  rsnContextCreate(int dev, int ver, int sdkVer, int contextType);
162add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams    synchronized int nContextCreate(int dev, int ver, int sdkVer, int contextType) {
163add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams        return rsnContextCreate(dev, ver, sdkVer, contextType);
1642e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1652e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextDestroy(int con);
1662e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextDestroy() {
167d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
1682e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextDestroy(mContext);
1692e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1702e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextSetSurface(int con, int w, int h, Surface sur);
1712e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextSetSurface(int w, int h, Surface sur) {
172d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
1732e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextSetSurface(mContext, w, h, sur);
1742e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
175faa32b33b50ad941f631716dd0915e936bdc3ac5Jason Sams    native void rsnContextSetSurfaceTexture(int con, int w, int h, SurfaceTexture sur);
176faa32b33b50ad941f631716dd0915e936bdc3ac5Jason Sams    synchronized void nContextSetSurfaceTexture(int w, int h, SurfaceTexture sur) {
177faa32b33b50ad941f631716dd0915e936bdc3ac5Jason Sams        validate();
178faa32b33b50ad941f631716dd0915e936bdc3ac5Jason Sams        rsnContextSetSurfaceTexture(mContext, w, h, sur);
179faa32b33b50ad941f631716dd0915e936bdc3ac5Jason Sams    }
1802e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextSetPriority(int con, int p);
1812e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextSetPriority(int p) {
182d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
1832e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextSetPriority(mContext, p);
1842e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1852e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextDump(int con, int bits);
1862e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextDump(int bits) {
187d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
1882e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextDump(mContext, bits);
1892e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1902e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextFinish(int con);
1912e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextFinish() {
192d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
1932e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextFinish(mContext);
1942e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1952e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
196455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams    native void rsnContextSendMessage(int con, int id, int[] data);
197455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams    synchronized void nContextSendMessage(int id, int[] data) {
198455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams        validate();
199455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams        rsnContextSendMessage(mContext, id, data);
200455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams    }
201455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams
2022e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextBindRootScript(int con, int script);
2032e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextBindRootScript(int script) {
204d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
2052e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextBindRootScript(mContext, script);
2062e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2072e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextBindSampler(int con, int sampler, int slot);
2082e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextBindSampler(int sampler, int slot) {
209d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
2102e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextBindSampler(mContext, sampler, slot);
2112e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2122e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextBindProgramStore(int con, int pfs);
2132e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextBindProgramStore(int pfs) {
214d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
2152e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextBindProgramStore(mContext, pfs);
2162e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2172e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextBindProgramFragment(int con, int pf);
2182e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextBindProgramFragment(int pf) {
219d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
2202e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextBindProgramFragment(mContext, pf);
2212e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2222e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextBindProgramVertex(int con, int pv);
2232e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextBindProgramVertex(int pv) {
224d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
2252e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextBindProgramVertex(mContext, pv);
2262e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2272e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextBindProgramRaster(int con, int pr);
2282e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextBindProgramRaster(int pr) {
229d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
2302e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextBindProgramRaster(mContext, pr);
2312e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2322e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextPause(int con);
2332e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextPause() {
234d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
2352e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextPause(mContext);
2362e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2372e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextResume(int con);
2382e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextResume() {
239d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
2402e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextResume(mContext);
2412e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2422e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
2432e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAssignName(int con, int obj, byte[] name);
2442e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAssignName(int obj, byte[] name) {
245d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
2462e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAssignName(mContext, obj, name);
2472e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2482e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native String rsnGetName(int con, int obj);
2492e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized String nGetName(int obj) {
250d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
2512e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnGetName(mContext, obj);
2522e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2532e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnObjDestroy(int con, int id);
2542e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nObjDestroy(int id) {
255d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        // There is a race condition here.  The calling code may be run
256d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        // by the gc while teardown is occuring.  This protects againts
257d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        // deleting dead objects.
258d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        if (mContext != 0) {
259d1ac98149737299513da1357e36f68cbb6d74425Jason Sams            rsnObjDestroy(mContext, id);
260d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        }
2612e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2622e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
2632e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnElementCreate(int con, int type, int kind, boolean norm, int vecSize);
2642e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nElementCreate(int type, int kind, boolean norm, int vecSize) {
265d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
2662e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnElementCreate(mContext, type, kind, norm, vecSize);
2672e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
26870d4e5024298f71edb3b04867e05568f5495b4ceJason Sams    native int  rsnElementCreate2(int con, int[] elements, String[] names, int[] arraySizes);
26970d4e5024298f71edb3b04867e05568f5495b4ceJason Sams    synchronized int nElementCreate2(int[] elements, String[] names, int[] arraySizes) {
270d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
27170d4e5024298f71edb3b04867e05568f5495b4ceJason Sams        return rsnElementCreate2(mContext, elements, names, arraySizes);
2722e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2732e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnElementGetNativeData(int con, int id, int[] elementData);
2742e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nElementGetNativeData(int id, int[] elementData) {
275d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
2762e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnElementGetNativeData(mContext, id, elementData);
2772e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2787d5f5e7c8943e043a422ad51c85d4e1684c37e28Alex Sakhartchouk    native void rsnElementGetSubElements(int con, int id,
2797d5f5e7c8943e043a422ad51c85d4e1684c37e28Alex Sakhartchouk                                         int[] IDs, String[] names, int[] arraySizes);
2807d5f5e7c8943e043a422ad51c85d4e1684c37e28Alex Sakhartchouk    synchronized void nElementGetSubElements(int id, int[] IDs, String[] names, int[] arraySizes) {
281d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
2827d5f5e7c8943e043a422ad51c85d4e1684c37e28Alex Sakhartchouk        rsnElementGetSubElements(mContext, id, IDs, names, arraySizes);
2832e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2842e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
285b109cc78616abee7291eb42094cd156b5db3355dJason Sams    native int rsnTypeCreate(int con, int eid, int x, int y, int z, boolean mips, boolean faces, int yuv);
286b109cc78616abee7291eb42094cd156b5db3355dJason Sams    synchronized int nTypeCreate(int eid, int x, int y, int z, boolean mips, boolean faces, int yuv) {
287d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
288b109cc78616abee7291eb42094cd156b5db3355dJason Sams        return rsnTypeCreate(mContext, eid, x, y, z, mips, faces, yuv);
2892e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2902e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnTypeGetNativeData(int con, int id, int[] typeData);
2912e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nTypeGetNativeData(int id, int[] typeData) {
292d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
2932e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnTypeGetNativeData(mContext, id, typeData);
2942e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2952e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
296857d0c7017da763a420e825fffa2f260eb982c97Jason Sams    native int  rsnAllocationCreateTyped(int con, int type, int mip, int usage, int pointer);
297857d0c7017da763a420e825fffa2f260eb982c97Jason Sams    synchronized int nAllocationCreateTyped(int type, int mip, int usage, int pointer) {
298d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
299857d0c7017da763a420e825fffa2f260eb982c97Jason Sams        return rsnAllocationCreateTyped(mContext, type, mip, usage, pointer);
3002e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3015476b450e50939940dcf3f15c92335cee2fc572dJason Sams    native int  rsnAllocationCreateFromBitmap(int con, int type, int mip, Bitmap bmp, int usage);
3025476b450e50939940dcf3f15c92335cee2fc572dJason Sams    synchronized int nAllocationCreateFromBitmap(int type, int mip, Bitmap bmp, int usage) {
303d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
3045476b450e50939940dcf3f15c92335cee2fc572dJason Sams        return rsnAllocationCreateFromBitmap(mContext, type, mip, bmp, usage);
30526ae3904e8050eae655722caf93ee5d3f0ab195aAlex Sakhartchouk    }
306a314551d69098537337c970da615a8f8af58e1f1Tim Murray
307a314551d69098537337c970da615a8f8af58e1f1Tim Murray    native int  rsnAllocationCreateBitmapBackedAllocation(int con, int type, int mip, Bitmap bmp, int usage);
308a314551d69098537337c970da615a8f8af58e1f1Tim Murray    synchronized int nAllocationCreateBitmapBackedAllocation(int type, int mip, Bitmap bmp, int usage) {
309a314551d69098537337c970da615a8f8af58e1f1Tim Murray        validate();
310a314551d69098537337c970da615a8f8af58e1f1Tim Murray        return rsnAllocationCreateBitmapBackedAllocation(mContext, type, mip, bmp, usage);
311a314551d69098537337c970da615a8f8af58e1f1Tim Murray    }
312a314551d69098537337c970da615a8f8af58e1f1Tim Murray
313a314551d69098537337c970da615a8f8af58e1f1Tim Murray
3145476b450e50939940dcf3f15c92335cee2fc572dJason Sams    native int  rsnAllocationCubeCreateFromBitmap(int con, int type, int mip, Bitmap bmp, int usage);
3155476b450e50939940dcf3f15c92335cee2fc572dJason Sams    synchronized int nAllocationCubeCreateFromBitmap(int type, int mip, Bitmap bmp, int usage) {
316d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
3175476b450e50939940dcf3f15c92335cee2fc572dJason Sams        return rsnAllocationCubeCreateFromBitmap(mContext, type, mip, bmp, usage);
31867f2e442a31b8395e3c1951f8e91139ec7f2be99Alex Sakhartchouk    }
3192e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnAllocationCreateBitmapRef(int con, int type, Bitmap bmp);
3202e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nAllocationCreateBitmapRef(int type, Bitmap bmp) {
321d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
3222e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnAllocationCreateBitmapRef(mContext, type, bmp);
3232e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3245476b450e50939940dcf3f15c92335cee2fc572dJason Sams    native int  rsnAllocationCreateFromAssetStream(int con, int mips, int assetStream, int usage);
3255476b450e50939940dcf3f15c92335cee2fc572dJason Sams    synchronized int nAllocationCreateFromAssetStream(int mips, int assetStream, int usage) {
326d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
3275476b450e50939940dcf3f15c92335cee2fc572dJason Sams        return rsnAllocationCreateFromAssetStream(mContext, mips, assetStream, usage);
3285476b450e50939940dcf3f15c92335cee2fc572dJason Sams    }
3295476b450e50939940dcf3f15c92335cee2fc572dJason Sams
3304ef6650bd05a39a09958ea1db92f120ea4949cb1Jason Sams    native void  rsnAllocationCopyToBitmap(int con, int alloc, Bitmap bmp);
3314ef6650bd05a39a09958ea1db92f120ea4949cb1Jason Sams    synchronized void nAllocationCopyToBitmap(int alloc, Bitmap bmp) {
332d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
3334ef6650bd05a39a09958ea1db92f120ea4949cb1Jason Sams        rsnAllocationCopyToBitmap(mContext, alloc, bmp);
3344ef6650bd05a39a09958ea1db92f120ea4949cb1Jason Sams    }
3354ef6650bd05a39a09958ea1db92f120ea4949cb1Jason Sams
3364ef6650bd05a39a09958ea1db92f120ea4949cb1Jason Sams
3375476b450e50939940dcf3f15c92335cee2fc572dJason Sams    native void rsnAllocationSyncAll(int con, int alloc, int src);
3385476b450e50939940dcf3f15c92335cee2fc572dJason Sams    synchronized void nAllocationSyncAll(int alloc, int src) {
339d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
3405476b450e50939940dcf3f15c92335cee2fc572dJason Sams        rsnAllocationSyncAll(mContext, alloc, src);
3415476b450e50939940dcf3f15c92335cee2fc572dJason Sams    }
34272226e0543461133b9e177a3e78ae50b0c65e797Jason Sams    native Surface rsnAllocationGetSurface(int con, int alloc);
34372226e0543461133b9e177a3e78ae50b0c65e797Jason Sams    synchronized Surface nAllocationGetSurface(int alloc) {
344615e7cee03d1a53072b0369fa9f247811ac56845Jason Sams        validate();
34572226e0543461133b9e177a3e78ae50b0c65e797Jason Sams        return rsnAllocationGetSurface(mContext, alloc);
346fe1d5ffd1b6c4977a9f301997d2ad90e5b049a3bJason Sams    }
347fb9aa9f3ef11878caaf6fcfb5ea49ffb9f7abf33Jason Sams    native void rsnAllocationSetSurface(int con, int alloc, Surface sur);
348fb9aa9f3ef11878caaf6fcfb5ea49ffb9f7abf33Jason Sams    synchronized void nAllocationSetSurface(int alloc, Surface sur) {
349163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams        validate();
350fb9aa9f3ef11878caaf6fcfb5ea49ffb9f7abf33Jason Sams        rsnAllocationSetSurface(mContext, alloc, sur);
351163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams    }
352163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams    native void rsnAllocationIoSend(int con, int alloc);
353163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams    synchronized void nAllocationIoSend(int alloc) {
354163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams        validate();
355163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams        rsnAllocationIoSend(mContext, alloc);
356163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams    }
357163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams    native void rsnAllocationIoReceive(int con, int alloc);
358163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams    synchronized void nAllocationIoReceive(int alloc) {
359163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams        validate();
360163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams        rsnAllocationIoReceive(mContext, alloc);
361163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams    }
362163766cbe798baf8e86eb8201bc6c3def931d59aJason Sams
363615e7cee03d1a53072b0369fa9f247811ac56845Jason Sams
364f7086090cfc8d97b5bd3b4d7801a27af11f7c207Jason Sams    native void rsnAllocationGenerateMipmaps(int con, int alloc);
365f7086090cfc8d97b5bd3b4d7801a27af11f7c207Jason Sams    synchronized void nAllocationGenerateMipmaps(int alloc) {
366d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
367f7086090cfc8d97b5bd3b4d7801a27af11f7c207Jason Sams        rsnAllocationGenerateMipmaps(mContext, alloc);
368f7086090cfc8d97b5bd3b4d7801a27af11f7c207Jason Sams    }
3694ef6650bd05a39a09958ea1db92f120ea4949cb1Jason Sams    native void  rsnAllocationCopyFromBitmap(int con, int alloc, Bitmap bmp);
3704ef6650bd05a39a09958ea1db92f120ea4949cb1Jason Sams    synchronized void nAllocationCopyFromBitmap(int alloc, Bitmap bmp) {
371d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
3724ef6650bd05a39a09958ea1db92f120ea4949cb1Jason Sams        rsnAllocationCopyFromBitmap(mContext, alloc, bmp);
3732e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3742e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
3752e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
37649a05d7b82956009f03acbb92a064eed054eb031Jason Sams    native void rsnAllocationData1D(int con, int id, int off, int mip, int count, int[] d, int sizeBytes);
37749a05d7b82956009f03acbb92a064eed054eb031Jason Sams    synchronized void nAllocationData1D(int id, int off, int mip, int count, int[] d, int sizeBytes) {
378d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
37949a05d7b82956009f03acbb92a064eed054eb031Jason Sams        rsnAllocationData1D(mContext, id, off, mip, count, d, sizeBytes);
3802e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
38149a05d7b82956009f03acbb92a064eed054eb031Jason Sams    native void rsnAllocationData1D(int con, int id, int off, int mip, int count, short[] d, int sizeBytes);
38249a05d7b82956009f03acbb92a064eed054eb031Jason Sams    synchronized void nAllocationData1D(int id, int off, int mip, int count, short[] d, int sizeBytes) {
383d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
38449a05d7b82956009f03acbb92a064eed054eb031Jason Sams        rsnAllocationData1D(mContext, id, off, mip, count, d, sizeBytes);
3852e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
38649a05d7b82956009f03acbb92a064eed054eb031Jason Sams    native void rsnAllocationData1D(int con, int id, int off, int mip, int count, byte[] d, int sizeBytes);
38749a05d7b82956009f03acbb92a064eed054eb031Jason Sams    synchronized void nAllocationData1D(int id, int off, int mip, int count, byte[] d, int sizeBytes) {
388d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
38949a05d7b82956009f03acbb92a064eed054eb031Jason Sams        rsnAllocationData1D(mContext, id, off, mip, count, d, sizeBytes);
3902e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
39149a05d7b82956009f03acbb92a064eed054eb031Jason Sams    native void rsnAllocationData1D(int con, int id, int off, int mip, int count, float[] d, int sizeBytes);
39249a05d7b82956009f03acbb92a064eed054eb031Jason Sams    synchronized void nAllocationData1D(int id, int off, int mip, int count, float[] d, int sizeBytes) {
393d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
39449a05d7b82956009f03acbb92a064eed054eb031Jason Sams        rsnAllocationData1D(mContext, id, off, mip, count, d, sizeBytes);
39549bdaf0293408159df18a1d8540360f9623c40f7Jason Sams    }
39649a05d7b82956009f03acbb92a064eed054eb031Jason Sams
39749a05d7b82956009f03acbb92a064eed054eb031Jason Sams    native void rsnAllocationElementData1D(int con, int id, int xoff, int mip, int compIdx, byte[] d, int sizeBytes);
39849a05d7b82956009f03acbb92a064eed054eb031Jason Sams    synchronized void nAllocationElementData1D(int id, int xoff, int mip, int compIdx, byte[] d, int sizeBytes) {
399d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
40049a05d7b82956009f03acbb92a064eed054eb031Jason Sams        rsnAllocationElementData1D(mContext, id, xoff, mip, compIdx, d, sizeBytes);
4012e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4022e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
403304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk    native void rsnAllocationData2D(int con,
404304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                                    int dstAlloc, int dstXoff, int dstYoff,
405304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                                    int dstMip, int dstFace,
406304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                                    int width, int height,
407304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                                    int srcAlloc, int srcXoff, int srcYoff,
408304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                                    int srcMip, int srcFace);
409304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk    synchronized void nAllocationData2D(int dstAlloc, int dstXoff, int dstYoff,
410304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                                        int dstMip, int dstFace,
411304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                                        int width, int height,
412304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                                        int srcAlloc, int srcXoff, int srcYoff,
413304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                                        int srcMip, int srcFace) {
414304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk        validate();
415304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk        rsnAllocationData2D(mContext,
416304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                            dstAlloc, dstXoff, dstYoff,
417304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                            dstMip, dstFace,
418304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                            width, height,
419304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                            srcAlloc, srcXoff, srcYoff,
420304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk                            srcMip, srcFace);
421304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk    }
422304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk
423fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    native void rsnAllocationData2D(int con, int id, int xoff, int yoff, int mip, int face, int w, int h, byte[] d, int sizeBytes);
424fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    synchronized void nAllocationData2D(int id, int xoff, int yoff, int mip, int face, int w, int h, byte[] d, int sizeBytes) {
425d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
426fa445b9353972735d8d65e8a936786b1afe9886dJason Sams        rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes);
427fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    }
428fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    native void rsnAllocationData2D(int con, int id, int xoff, int yoff, int mip, int face, int w, int h, short[] d, int sizeBytes);
429fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    synchronized void nAllocationData2D(int id, int xoff, int yoff, int mip, int face, int w, int h, short[] d, int sizeBytes) {
430d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
431fa445b9353972735d8d65e8a936786b1afe9886dJason Sams        rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes);
432fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    }
43349a05d7b82956009f03acbb92a064eed054eb031Jason Sams    native void rsnAllocationData2D(int con, int id, int xoff, int yoff, int mip, int face, int w, int h, int[] d, int sizeBytes);
43449a05d7b82956009f03acbb92a064eed054eb031Jason Sams    synchronized void nAllocationData2D(int id, int xoff, int yoff, int mip, int face, int w, int h, int[] d, int sizeBytes) {
435d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
43649a05d7b82956009f03acbb92a064eed054eb031Jason Sams        rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes);
4372e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
43849a05d7b82956009f03acbb92a064eed054eb031Jason Sams    native void rsnAllocationData2D(int con, int id, int xoff, int yoff, int mip, int face, int w, int h, float[] d, int sizeBytes);
43949a05d7b82956009f03acbb92a064eed054eb031Jason Sams    synchronized void nAllocationData2D(int id, int xoff, int yoff, int mip, int face, int w, int h, float[] d, int sizeBytes) {
440d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
44149a05d7b82956009f03acbb92a064eed054eb031Jason Sams        rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes);
4422e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
443fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    native void rsnAllocationData2D(int con, int id, int xoff, int yoff, int mip, int face, Bitmap b);
444fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    synchronized void nAllocationData2D(int id, int xoff, int yoff, int mip, int face, Bitmap b) {
445d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
446fa445b9353972735d8d65e8a936786b1afe9886dJason Sams        rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, b);
447fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    }
44849a05d7b82956009f03acbb92a064eed054eb031Jason Sams
449b05d689653b1bc94836f716f29e9578677c29075Jason Sams    native void rsnAllocationData3D(int con,
450b05d689653b1bc94836f716f29e9578677c29075Jason Sams                                    int dstAlloc, int dstXoff, int dstYoff, int dstZoff,
451b05d689653b1bc94836f716f29e9578677c29075Jason Sams                                    int dstMip,
452b05d689653b1bc94836f716f29e9578677c29075Jason Sams                                    int width, int height, int depth,
453b05d689653b1bc94836f716f29e9578677c29075Jason Sams                                    int srcAlloc, int srcXoff, int srcYoff, int srcZoff,
454b05d689653b1bc94836f716f29e9578677c29075Jason Sams                                    int srcMip);
455b05d689653b1bc94836f716f29e9578677c29075Jason Sams    synchronized void nAllocationData3D(int dstAlloc, int dstXoff, int dstYoff, int dstZoff,
456b05d689653b1bc94836f716f29e9578677c29075Jason Sams                                        int dstMip,
457b05d689653b1bc94836f716f29e9578677c29075Jason Sams                                        int width, int height, int depth,
458b05d689653b1bc94836f716f29e9578677c29075Jason Sams                                        int srcAlloc, int srcXoff, int srcYoff, int srcZoff,
459b05d689653b1bc94836f716f29e9578677c29075Jason Sams                                        int srcMip) {
460b05d689653b1bc94836f716f29e9578677c29075Jason Sams        validate();
461b05d689653b1bc94836f716f29e9578677c29075Jason Sams        rsnAllocationData3D(mContext,
462b05d689653b1bc94836f716f29e9578677c29075Jason Sams                            dstAlloc, dstXoff, dstYoff, dstZoff,
463b05d689653b1bc94836f716f29e9578677c29075Jason Sams                            dstMip, width, height, depth,
464b05d689653b1bc94836f716f29e9578677c29075Jason Sams                            srcAlloc, srcXoff, srcYoff, srcZoff, srcMip);
465b05d689653b1bc94836f716f29e9578677c29075Jason Sams    }
466b05d689653b1bc94836f716f29e9578677c29075Jason Sams
467b05d689653b1bc94836f716f29e9578677c29075Jason Sams    native void rsnAllocationData3D(int con, int id, int xoff, int yoff, int zoff, int mip, int w, int h, int depth, byte[] d, int sizeBytes);
468b05d689653b1bc94836f716f29e9578677c29075Jason Sams    synchronized void nAllocationData3D(int id, int xoff, int yoff, int zoff, int mip, int w, int h, int depth, byte[] d, int sizeBytes) {
469b05d689653b1bc94836f716f29e9578677c29075Jason Sams        validate();
470b05d689653b1bc94836f716f29e9578677c29075Jason Sams        rsnAllocationData3D(mContext, id, xoff, yoff, zoff, mip, w, h, depth, d, sizeBytes);
471b05d689653b1bc94836f716f29e9578677c29075Jason Sams    }
472b05d689653b1bc94836f716f29e9578677c29075Jason Sams    native void rsnAllocationData3D(int con, int id, int xoff, int yoff, int zoff, int mip, int w, int h, int depth, short[] d, int sizeBytes);
473b05d689653b1bc94836f716f29e9578677c29075Jason Sams    synchronized void nAllocationData3D(int id, int xoff, int yoff, int zoff, int mip, int w, int h, int depth, short[] d, int sizeBytes) {
474b05d689653b1bc94836f716f29e9578677c29075Jason Sams        validate();
475b05d689653b1bc94836f716f29e9578677c29075Jason Sams        rsnAllocationData3D(mContext, id, xoff, yoff, zoff, mip, w, h, depth, d, sizeBytes);
476b05d689653b1bc94836f716f29e9578677c29075Jason Sams    }
477b05d689653b1bc94836f716f29e9578677c29075Jason Sams    native void rsnAllocationData3D(int con, int id, int xoff, int yoff, int zoff, int mip, int w, int h, int depth, int[] d, int sizeBytes);
478b05d689653b1bc94836f716f29e9578677c29075Jason Sams    synchronized void nAllocationData3D(int id, int xoff, int yoff, int zoff, int mip, int w, int h, int depth, int[] d, int sizeBytes) {
479b05d689653b1bc94836f716f29e9578677c29075Jason Sams        validate();
480b05d689653b1bc94836f716f29e9578677c29075Jason Sams        rsnAllocationData3D(mContext, id, xoff, yoff, zoff, mip, w, h, depth, d, sizeBytes);
481b05d689653b1bc94836f716f29e9578677c29075Jason Sams    }
482b05d689653b1bc94836f716f29e9578677c29075Jason Sams    native void rsnAllocationData3D(int con, int id, int xoff, int yoff, int zoff, int mip, int w, int h, int depth, float[] d, int sizeBytes);
483b05d689653b1bc94836f716f29e9578677c29075Jason Sams    synchronized void nAllocationData3D(int id, int xoff, int yoff, int zoff, int mip, int w, int h, int depth, float[] d, int sizeBytes) {
484b05d689653b1bc94836f716f29e9578677c29075Jason Sams        validate();
485b05d689653b1bc94836f716f29e9578677c29075Jason Sams        rsnAllocationData3D(mContext, id, xoff, yoff, zoff, mip, w, h, depth, d, sizeBytes);
486b05d689653b1bc94836f716f29e9578677c29075Jason Sams    }
487b05d689653b1bc94836f716f29e9578677c29075Jason Sams
488b05d689653b1bc94836f716f29e9578677c29075Jason Sams
489fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    native void rsnAllocationRead(int con, int id, byte[] d);
490fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    synchronized void nAllocationRead(int id, byte[] d) {
491d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
492fa445b9353972735d8d65e8a936786b1afe9886dJason Sams        rsnAllocationRead(mContext, id, d);
493fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    }
494fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    native void rsnAllocationRead(int con, int id, short[] d);
495fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    synchronized void nAllocationRead(int id, short[] d) {
496d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
497fa445b9353972735d8d65e8a936786b1afe9886dJason Sams        rsnAllocationRead(mContext, id, d);
498fa445b9353972735d8d65e8a936786b1afe9886dJason Sams    }
4992e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAllocationRead(int con, int id, int[] d);
5002e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAllocationRead(int id, int[] d) {
501d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
5022e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAllocationRead(mContext, id, d);
5032e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
5042e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAllocationRead(int con, int id, float[] d);
5052e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAllocationRead(int id, float[] d) {
506d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
5072e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAllocationRead(mContext, id, d);
5082e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
5092e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnAllocationGetType(int con, int id);
5102e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nAllocationGetType(int id) {
511d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
5122e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnAllocationGetType(mContext, id);
5132e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
5142e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
5155edc608a0749ed4b7074b5c1243043eb722c3c31Jason Sams    native void rsnAllocationResize1D(int con, int id, int dimX);
5165edc608a0749ed4b7074b5c1243043eb722c3c31Jason Sams    synchronized void nAllocationResize1D(int id, int dimX) {
517d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
5185edc608a0749ed4b7074b5c1243043eb722c3c31Jason Sams        rsnAllocationResize1D(mContext, id, dimX);
5195edc608a0749ed4b7074b5c1243043eb722c3c31Jason Sams    }
5205edc608a0749ed4b7074b5c1243043eb722c3c31Jason Sams
5212e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnFileA3DCreateFromAssetStream(int con, int assetStream);
5222e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nFileA3DCreateFromAssetStream(int assetStream) {
523d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
5242e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnFileA3DCreateFromAssetStream(mContext, assetStream);
5252e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
526b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    native int  rsnFileA3DCreateFromFile(int con, String path);
527b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    synchronized int nFileA3DCreateFromFile(String path) {
528d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
529b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk        return rsnFileA3DCreateFromFile(mContext, path);
530b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    }
531b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    native int  rsnFileA3DCreateFromAsset(int con, AssetManager mgr, String path);
532b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    synchronized int nFileA3DCreateFromAsset(AssetManager mgr, String path) {
533d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
534b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk        return rsnFileA3DCreateFromAsset(mContext, mgr, path);
535b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    }
5362e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnFileA3DGetNumIndexEntries(int con, int fileA3D);
5372e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nFileA3DGetNumIndexEntries(int fileA3D) {
538d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
5392e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnFileA3DGetNumIndexEntries(mContext, fileA3D);
5402e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
5412e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnFileA3DGetIndexEntries(int con, int fileA3D, int numEntries, int[] IDs, String[] names);
5422e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nFileA3DGetIndexEntries(int fileA3D, int numEntries, int[] IDs, String[] names) {
543d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
5442e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnFileA3DGetIndexEntries(mContext, fileA3D, numEntries, IDs, names);
5452e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
5462e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnFileA3DGetEntryByIndex(int con, int fileA3D, int index);
5472e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nFileA3DGetEntryByIndex(int fileA3D, int index) {
548d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
5492e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnFileA3DGetEntryByIndex(mContext, fileA3D, index);
5502e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
5512e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
552e27cdeeecba5b445e307d653d9cb7da007adfac3Alex Sakhartchouk    native int  rsnFontCreateFromFile(int con, String fileName, float size, int dpi);
553e27cdeeecba5b445e307d653d9cb7da007adfac3Alex Sakhartchouk    synchronized int nFontCreateFromFile(String fileName, float size, int dpi) {
554d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
5552e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnFontCreateFromFile(mContext, fileName, size, dpi);
5562e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
557b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    native int  rsnFontCreateFromAssetStream(int con, String name, float size, int dpi, int assetStream);
558b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    synchronized int nFontCreateFromAssetStream(String name, float size, int dpi, int assetStream) {
559d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
560b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk        return rsnFontCreateFromAssetStream(mContext, name, size, dpi, assetStream);
561b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    }
562b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    native int  rsnFontCreateFromAsset(int con, AssetManager mgr, String path, float size, int dpi);
563b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    synchronized int nFontCreateFromAsset(AssetManager mgr, String path, float size, int dpi) {
564d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
565b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk        return rsnFontCreateFromAsset(mContext, mgr, path, size, dpi);
566b0253ea6969bdd27bf574e0da7fa91aa6d09f44fAlex Sakhartchouk    }
5672e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
5682e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
5692e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnScriptBindAllocation(int con, int script, int alloc, int slot);
5702e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nScriptBindAllocation(int script, int alloc, int slot) {
571d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
5722e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnScriptBindAllocation(mContext, script, alloc, slot);
5732e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
5742e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnScriptSetTimeZone(int con, int script, byte[] timeZone);
5752e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nScriptSetTimeZone(int script, byte[] timeZone) {
576d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
5772e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnScriptSetTimeZone(mContext, script, timeZone);
5782e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
5792e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnScriptInvoke(int con, int id, int slot);
5802e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nScriptInvoke(int id, int slot) {
581d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
5822e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnScriptInvoke(mContext, id, slot);
5832e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
5846e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams    native void rsnScriptForEach(int con, int id, int slot, int ain, int aout, byte[] params);
5856e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams    native void rsnScriptForEach(int con, int id, int slot, int ain, int aout);
586eb8c29cb7ece3f4b7ad18e5393b07fa7418a541cTim Murray    native void rsnScriptForEachClipped(int con, int id, int slot, int ain, int aout, byte[] params,
587eb8c29cb7ece3f4b7ad18e5393b07fa7418a541cTim Murray                                        int xstart, int xend, int ystart, int yend, int zstart, int zend);
588dac6ed0b69b23ab25757085dd5ce68092516ee2fStephen Hines    native void rsnScriptForEachClipped(int con, int id, int slot, int ain, int aout,
589dac6ed0b69b23ab25757085dd5ce68092516ee2fStephen Hines                                        int xstart, int xend, int ystart, int yend, int zstart, int zend);
5906e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams    synchronized void nScriptForEach(int id, int slot, int ain, int aout, byte[] params) {
5916e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams        validate();
5926e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams        if (params == null) {
5936e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams            rsnScriptForEach(mContext, id, slot, ain, aout);
5946e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams        } else {
5956e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams            rsnScriptForEach(mContext, id, slot, ain, aout, params);
5966e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams        }
5976e494d3ab606be8c06f8d4930fbec572bbfa15c2Jason Sams    }
598eb8c29cb7ece3f4b7ad18e5393b07fa7418a541cTim Murray
599eb8c29cb7ece3f4b7ad18e5393b07fa7418a541cTim Murray    synchronized void nScriptForEachClipped(int id, int slot, int ain, int aout, byte[] params,
600eb8c29cb7ece3f4b7ad18e5393b07fa7418a541cTim Murray                                            int xstart, int xend, int ystart, int yend, int zstart, int zend) {
601eb8c29cb7ece3f4b7ad18e5393b07fa7418a541cTim Murray        validate();
602dac6ed0b69b23ab25757085dd5ce68092516ee2fStephen Hines        if (params == null) {
603dac6ed0b69b23ab25757085dd5ce68092516ee2fStephen Hines            rsnScriptForEachClipped(mContext, id, slot, ain, aout, xstart, xend, ystart, yend, zstart, zend);
604dac6ed0b69b23ab25757085dd5ce68092516ee2fStephen Hines        } else {
605dac6ed0b69b23ab25757085dd5ce68092516ee2fStephen Hines            rsnScriptForEachClipped(mContext, id, slot, ain, aout, params, xstart, xend, ystart, yend, zstart, zend);
606dac6ed0b69b23ab25757085dd5ce68092516ee2fStephen Hines        }
607eb8c29cb7ece3f4b7ad18e5393b07fa7418a541cTim Murray    }
608eb8c29cb7ece3f4b7ad18e5393b07fa7418a541cTim Murray
6092e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnScriptInvokeV(int con, int id, int slot, byte[] params);
6102e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nScriptInvokeV(int id, int slot, byte[] params) {
611d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
6122e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnScriptInvokeV(mContext, id, slot, params);
6132e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
6147c4caadb939b1563328251c156262c179a685c70Tim Murray
6152e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnScriptSetVarI(int con, int id, int slot, int val);
6162e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nScriptSetVarI(int id, int slot, int val) {
617d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
6182e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnScriptSetVarI(mContext, id, slot, val);
6192e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
6207c4caadb939b1563328251c156262c179a685c70Tim Murray    native int rsnScriptGetVarI(int con, int id, int slot);
6217c4caadb939b1563328251c156262c179a685c70Tim Murray    synchronized int nScriptGetVarI(int id, int slot) {
6227c4caadb939b1563328251c156262c179a685c70Tim Murray        validate();
6237c4caadb939b1563328251c156262c179a685c70Tim Murray        return rsnScriptGetVarI(mContext, id, slot);
6247c4caadb939b1563328251c156262c179a685c70Tim Murray    }
6257c4caadb939b1563328251c156262c179a685c70Tim Murray
626031ec58cfc7a20927302a5300eba3f5fc1709b50Stephen Hines    native void rsnScriptSetVarJ(int con, int id, int slot, long val);
627031ec58cfc7a20927302a5300eba3f5fc1709b50Stephen Hines    synchronized void nScriptSetVarJ(int id, int slot, long val) {
628d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
629031ec58cfc7a20927302a5300eba3f5fc1709b50Stephen Hines        rsnScriptSetVarJ(mContext, id, slot, val);
630031ec58cfc7a20927302a5300eba3f5fc1709b50Stephen Hines    }
6317c4caadb939b1563328251c156262c179a685c70Tim Murray    native long rsnScriptGetVarJ(int con, int id, int slot);
6327c4caadb939b1563328251c156262c179a685c70Tim Murray    synchronized long nScriptGetVarJ(int id, int slot) {
6337c4caadb939b1563328251c156262c179a685c70Tim Murray        validate();
6347c4caadb939b1563328251c156262c179a685c70Tim Murray        return rsnScriptGetVarJ(mContext, id, slot);
6357c4caadb939b1563328251c156262c179a685c70Tim Murray    }
6367c4caadb939b1563328251c156262c179a685c70Tim Murray
6372e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnScriptSetVarF(int con, int id, int slot, float val);
6382e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nScriptSetVarF(int id, int slot, float val) {
639d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
6402e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnScriptSetVarF(mContext, id, slot, val);
6412e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
6427c4caadb939b1563328251c156262c179a685c70Tim Murray    native float rsnScriptGetVarF(int con, int id, int slot);
6437c4caadb939b1563328251c156262c179a685c70Tim Murray    synchronized float nScriptGetVarF(int id, int slot) {
6447c4caadb939b1563328251c156262c179a685c70Tim Murray        validate();
6457c4caadb939b1563328251c156262c179a685c70Tim Murray        return rsnScriptGetVarF(mContext, id, slot);
6467c4caadb939b1563328251c156262c179a685c70Tim Murray    }
647ca54ec302f5bddd1674ea1f36cd3b7c540b2fbcaStephen Hines    native void rsnScriptSetVarD(int con, int id, int slot, double val);
648ca54ec302f5bddd1674ea1f36cd3b7c540b2fbcaStephen Hines    synchronized void nScriptSetVarD(int id, int slot, double val) {
649d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
650ca54ec302f5bddd1674ea1f36cd3b7c540b2fbcaStephen Hines        rsnScriptSetVarD(mContext, id, slot, val);
651ca54ec302f5bddd1674ea1f36cd3b7c540b2fbcaStephen Hines    }
6527c4caadb939b1563328251c156262c179a685c70Tim Murray    native double rsnScriptGetVarD(int con, int id, int slot);
6537c4caadb939b1563328251c156262c179a685c70Tim Murray    synchronized double nScriptGetVarD(int id, int slot) {
6547c4caadb939b1563328251c156262c179a685c70Tim Murray        validate();
6557c4caadb939b1563328251c156262c179a685c70Tim Murray        return rsnScriptGetVarD(mContext, id, slot);
6567c4caadb939b1563328251c156262c179a685c70Tim Murray    }
6572e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnScriptSetVarV(int con, int id, int slot, byte[] val);
6582e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nScriptSetVarV(int id, int slot, byte[] val) {
659d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
6602e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnScriptSetVarV(mContext, id, slot, val);
6612e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
6627c4caadb939b1563328251c156262c179a685c70Tim Murray    native void rsnScriptGetVarV(int con, int id, int slot, byte[] val);
6637c4caadb939b1563328251c156262c179a685c70Tim Murray    synchronized void nScriptGetVarV(int id, int slot, byte[] val) {
6647c4caadb939b1563328251c156262c179a685c70Tim Murray        validate();
6657c4caadb939b1563328251c156262c179a685c70Tim Murray        rsnScriptGetVarV(mContext, id, slot, val);
6667c4caadb939b1563328251c156262c179a685c70Tim Murray    }
667adeb809201fcb77ba2b76a814ae4cdc9dacb326bStephen Hines    native void rsnScriptSetVarVE(int con, int id, int slot, byte[] val,
668adeb809201fcb77ba2b76a814ae4cdc9dacb326bStephen Hines                                  int e, int[] dims);
669adeb809201fcb77ba2b76a814ae4cdc9dacb326bStephen Hines    synchronized void nScriptSetVarVE(int id, int slot, byte[] val,
670adeb809201fcb77ba2b76a814ae4cdc9dacb326bStephen Hines                                      int e, int[] dims) {
671adeb809201fcb77ba2b76a814ae4cdc9dacb326bStephen Hines        validate();
672adeb809201fcb77ba2b76a814ae4cdc9dacb326bStephen Hines        rsnScriptSetVarVE(mContext, id, slot, val, e, dims);
673adeb809201fcb77ba2b76a814ae4cdc9dacb326bStephen Hines    }
6746f4cf0b8885403ead157ae00fd43cf1282331c23Jason Sams    native void rsnScriptSetVarObj(int con, int id, int slot, int val);
6756f4cf0b8885403ead157ae00fd43cf1282331c23Jason Sams    synchronized void nScriptSetVarObj(int id, int slot, int val) {
676d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
6776f4cf0b8885403ead157ae00fd43cf1282331c23Jason Sams        rsnScriptSetVarObj(mContext, id, slot, val);
6786f4cf0b8885403ead157ae00fd43cf1282331c23Jason Sams    }
6792e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
680e4a06c5fc738bf219f2a495e12a637b2d0871651Jason Sams    native int  rsnScriptCCreate(int con, String resName, String cacheDir,
681e4a06c5fc738bf219f2a495e12a637b2d0871651Jason Sams                                 byte[] script, int length);
682e4a06c5fc738bf219f2a495e12a637b2d0871651Jason Sams    synchronized int nScriptCCreate(String resName, String cacheDir, byte[] script, int length) {
683d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
684e4a06c5fc738bf219f2a495e12a637b2d0871651Jason Sams        return rsnScriptCCreate(mContext, resName, cacheDir, script, length);
6852e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
6862e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
6876ab97682fd444586ee135912a4210417a1c8781bJason Sams    native int  rsnScriptIntrinsicCreate(int con, int id, int eid);
6886ab97682fd444586ee135912a4210417a1c8781bJason Sams    synchronized int nScriptIntrinsicCreate(int id, int eid) {
6896ab97682fd444586ee135912a4210417a1c8781bJason Sams        validate();
6906ab97682fd444586ee135912a4210417a1c8781bJason Sams        return rsnScriptIntrinsicCreate(mContext, id, eid);
6916ab97682fd444586ee135912a4210417a1c8781bJason Sams    }
6926ab97682fd444586ee135912a4210417a1c8781bJason Sams
69308a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    native int  rsnScriptKernelIDCreate(int con, int sid, int slot, int sig);
69408a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    synchronized int nScriptKernelIDCreate(int sid, int slot, int sig) {
69508a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams        validate();
69608a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams        return rsnScriptKernelIDCreate(mContext, sid, slot, sig);
69708a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    }
69808a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams
69908a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    native int  rsnScriptFieldIDCreate(int con, int sid, int slot);
70008a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    synchronized int nScriptFieldIDCreate(int sid, int slot) {
70108a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams        validate();
70208a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams        return rsnScriptFieldIDCreate(mContext, sid, slot);
70308a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    }
70408a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams
70508a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    native int  rsnScriptGroupCreate(int con, int[] kernels, int[] src, int[] dstk, int[] dstf, int[] types);
70608a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    synchronized int nScriptGroupCreate(int[] kernels, int[] src, int[] dstk, int[] dstf, int[] types) {
70708a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams        validate();
70808a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams        return rsnScriptGroupCreate(mContext, kernels, src, dstk, dstf, types);
70908a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    }
71008a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams
71108a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    native void rsnScriptGroupSetInput(int con, int group, int kernel, int alloc);
71208a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    synchronized void nScriptGroupSetInput(int group, int kernel, int alloc) {
71308a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams        validate();
71408a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams        rsnScriptGroupSetInput(mContext, group, kernel, alloc);
71508a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    }
71608a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams
71708a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    native void rsnScriptGroupSetOutput(int con, int group, int kernel, int alloc);
71808a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    synchronized void nScriptGroupSetOutput(int group, int kernel, int alloc) {
71908a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams        validate();
72008a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams        rsnScriptGroupSetOutput(mContext, group, kernel, alloc);
72108a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    }
72208a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams
72308a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    native void rsnScriptGroupExecute(int con, int group);
72408a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    synchronized void nScriptGroupExecute(int group) {
72508a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams        validate();
72608a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams        rsnScriptGroupExecute(mContext, group);
72708a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams    }
72808a81583c18a849e442ceeb8d7baeca743fb3be8Jason Sams
729a89094aa3bc059c6e03b20b4c5b1ede4582f3da9Alex Sakhartchouk    native int  rsnSamplerCreate(int con, int magFilter, int minFilter,
730a89094aa3bc059c6e03b20b4c5b1ede4582f3da9Alex Sakhartchouk                                 int wrapS, int wrapT, int wrapR, float aniso);
731a89094aa3bc059c6e03b20b4c5b1ede4582f3da9Alex Sakhartchouk    synchronized int nSamplerCreate(int magFilter, int minFilter,
732a89094aa3bc059c6e03b20b4c5b1ede4582f3da9Alex Sakhartchouk                                 int wrapS, int wrapT, int wrapR, float aniso) {
733d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
734a89094aa3bc059c6e03b20b4c5b1ede4582f3da9Alex Sakhartchouk        return rsnSamplerCreate(mContext, magFilter, minFilter, wrapS, wrapT, wrapR, aniso);
7352e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
7362e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
737331bf9b14b1c5c1e88f5c4092b6e24fae887fb3bJason Sams    native int  rsnProgramStoreCreate(int con, boolean r, boolean g, boolean b, boolean a,
738331bf9b14b1c5c1e88f5c4092b6e24fae887fb3bJason Sams                                      boolean depthMask, boolean dither,
739331bf9b14b1c5c1e88f5c4092b6e24fae887fb3bJason Sams                                      int srcMode, int dstMode, int depthFunc);
740331bf9b14b1c5c1e88f5c4092b6e24fae887fb3bJason Sams    synchronized int nProgramStoreCreate(boolean r, boolean g, boolean b, boolean a,
741331bf9b14b1c5c1e88f5c4092b6e24fae887fb3bJason Sams                                         boolean depthMask, boolean dither,
742331bf9b14b1c5c1e88f5c4092b6e24fae887fb3bJason Sams                                         int srcMode, int dstMode, int depthFunc) {
743d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
744bd184c55850997a5c5e285357998dadbe95b7b5dJason Sams        return rsnProgramStoreCreate(mContext, r, g, b, a, depthMask, dither, srcMode,
745bd184c55850997a5c5e285357998dadbe95b7b5dJason Sams                                     dstMode, depthFunc);
7462e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
7472e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
74894aaed38467c71a6c804f0e18b41346a4013c25bJason Sams    native int  rsnProgramRasterCreate(int con, boolean pointSprite, int cullMode);
74994aaed38467c71a6c804f0e18b41346a4013c25bJason Sams    synchronized int nProgramRasterCreate(boolean pointSprite, int cullMode) {
750d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
75194aaed38467c71a6c804f0e18b41346a4013c25bJason Sams        return rsnProgramRasterCreate(mContext, pointSprite, cullMode);
7522e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
7532e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
7542e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnProgramBindConstants(int con, int pv, int slot, int mID);
7552e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nProgramBindConstants(int pv, int slot, int mID) {
756d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
7572e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnProgramBindConstants(mContext, pv, slot, mID);
7582e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
7592e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnProgramBindTexture(int con, int vpf, int slot, int a);
7602e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nProgramBindTexture(int vpf, int slot, int a) {
761d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
7622e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnProgramBindTexture(mContext, vpf, slot, a);
7632e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
7642e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnProgramBindSampler(int con, int vpf, int slot, int s);
7652e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nProgramBindSampler(int vpf, int slot, int s) {
766d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
7672e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnProgramBindSampler(mContext, vpf, slot, s);
7682e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
7692123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk    native int  rsnProgramFragmentCreate(int con, String shader, String[] texNames, int[] params);
7702123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk    synchronized int nProgramFragmentCreate(String shader, String[] texNames, int[] params) {
771d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
7722123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk        return rsnProgramFragmentCreate(mContext, shader, texNames, params);
7732e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
7742123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk    native int  rsnProgramVertexCreate(int con, String shader, String[] texNames, int[] params);
7752123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk    synchronized int nProgramVertexCreate(String shader, String[] texNames, int[] params) {
776d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
7772123b46ba85adb2cfb78068f8368e830640118d3Alex Sakhartchouk        return rsnProgramVertexCreate(mContext, shader, texNames, params);
7782e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
7792e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
78025999a08a6652ff5d7d0973f279f1e92e04b3506Alex Sakhartchouk    native int  rsnMeshCreate(int con, int[] vtx, int[] idx, int[] prim);
78125999a08a6652ff5d7d0973f279f1e92e04b3506Alex Sakhartchouk    synchronized int nMeshCreate(int[] vtx, int[] idx, int[] prim) {
782d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
78325999a08a6652ff5d7d0973f279f1e92e04b3506Alex Sakhartchouk        return rsnMeshCreate(mContext, vtx, idx, prim);
7849d71e2180062931416092f26276a07e55b318f62Alex Sakhartchouk    }
7852e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnMeshGetVertexBufferCount(int con, int id);
7862e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nMeshGetVertexBufferCount(int id) {
787d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
7882e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnMeshGetVertexBufferCount(mContext, id);
7892e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
7902e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnMeshGetIndexCount(int con, int id);
7912e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nMeshGetIndexCount(int id) {
792d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
7932e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnMeshGetIndexCount(mContext, id);
7942e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
7952e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnMeshGetVertices(int con, int id, int[] vtxIds, int vtxIdCount);
7962e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nMeshGetVertices(int id, int[] vtxIds, int vtxIdCount) {
797d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
7982e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnMeshGetVertices(mContext, id, vtxIds, vtxIdCount);
7992e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
8002e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnMeshGetIndices(int con, int id, int[] idxIds, int[] primitives, int vtxIdCount);
8012e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nMeshGetIndices(int id, int[] idxIds, int[] primitives, int vtxIdCount) {
802d1ac98149737299513da1357e36f68cbb6d74425Jason Sams        validate();
8032e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnMeshGetIndices(mContext, id, idxIds, primitives, vtxIdCount);
8042e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
8052e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
806f15ed0124ea7f7f87e4188a1dd15cc4917a62ee9Jason Sams    native int  rsnPathCreate(int con, int prim, boolean isStatic, int vtx, int loop, float q);
807f15ed0124ea7f7f87e4188a1dd15cc4917a62ee9Jason Sams    synchronized int nPathCreate(int prim, boolean isStatic, int vtx, int loop, float q) {
808f15ed0124ea7f7f87e4188a1dd15cc4917a62ee9Jason Sams        validate();
809f15ed0124ea7f7f87e4188a1dd15cc4917a62ee9Jason Sams        return rsnPathCreate(mContext, prim, isStatic, vtx, loop, q);
810f15ed0124ea7f7f87e4188a1dd15cc4917a62ee9Jason Sams    }
81160aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
812bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    int     mDev;
813bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    int     mContext;
814650a3eb7d621dc8e81573142a4498bbd07bcde27Romain Guy    @SuppressWarnings({"FieldCanBeLocal"})
815bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    MessageThread mMessageThread;
81660aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
8178cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_U8;
8188cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_I8;
8198cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_U16;
8208cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_I16;
8218cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_U32;
8228cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_I32;
82352d836332f6aae74ed97fda1b53681f36710af64Stephen Hines    Element mElement_U64;
824ef1dac28d3bf98bd61cd9874fb3ccab42105e9b6Stephen Hines    Element mElement_I64;
8258cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_F32;
82602f41705199336f808ece50d81585450e7f8f61fStephen Hines    Element mElement_F64;
827f110d4b787b91dabe968a812e76e5c1f8d953487Jason Sams    Element mElement_BOOLEAN;
8288cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams
8298cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_ELEMENT;
8308cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_TYPE;
8318cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_ALLOCATION;
8328cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_SAMPLER;
8338cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_SCRIPT;
8348cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_MESH;
8358cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_PROGRAM_FRAGMENT;
8368cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_PROGRAM_VERTEX;
8378cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_PROGRAM_RASTER;
8388cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_PROGRAM_STORE;
8393a2914132146f340511425d7f78540098606b512Stephen Hines    Element mElement_FONT;
840a70f416c9cf2fc6cc5e132c1d656ce07441d6b82Jason Sams
8413c0dfbab807a459622aeade4940daddf482dec66Jason Sams    Element mElement_A_8;
8423c0dfbab807a459622aeade4940daddf482dec66Jason Sams    Element mElement_RGB_565;
8433c0dfbab807a459622aeade4940daddf482dec66Jason Sams    Element mElement_RGB_888;
8443c0dfbab807a459622aeade4940daddf482dec66Jason Sams    Element mElement_RGBA_5551;
8453c0dfbab807a459622aeade4940daddf482dec66Jason Sams    Element mElement_RGBA_4444;
8463c0dfbab807a459622aeade4940daddf482dec66Jason Sams    Element mElement_RGBA_8888;
8473c0dfbab807a459622aeade4940daddf482dec66Jason Sams
8488cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_FLOAT_2;
8498cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_FLOAT_3;
8508cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_FLOAT_4;
851836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines
852836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_DOUBLE_2;
853836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_DOUBLE_3;
854836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_DOUBLE_4;
855836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines
856836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_UCHAR_2;
857836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_UCHAR_3;
8588cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_UCHAR_4;
8597d787b4722eaeb79cab42c36060336e092b77b5fJason Sams
860836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_CHAR_2;
861836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_CHAR_3;
862836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_CHAR_4;
863836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines
864836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_USHORT_2;
865836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_USHORT_3;
866836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_USHORT_4;
867836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines
868836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_SHORT_2;
869836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_SHORT_3;
870836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_SHORT_4;
871836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines
872836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_UINT_2;
873836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_UINT_3;
874836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_UINT_4;
875836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines
876836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_INT_2;
877836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_INT_3;
878836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_INT_4;
879836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines
880836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_ULONG_2;
881836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_ULONG_3;
882836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_ULONG_4;
883836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines
884836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_LONG_2;
885836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_LONG_3;
886836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines    Element mElement_LONG_4;
887836c4a58a7f03485ef433dcdb61837cbc0c39735Stephen Hines
8881d45c47975ab2a8cef6db5a8976276de31e1e8d0Jason Sams    Element mElement_MATRIX_4X4;
8891d45c47975ab2a8cef6db5a8976276de31e1e8d0Jason Sams    Element mElement_MATRIX_3X3;
8901d45c47975ab2a8cef6db5a8976276de31e1e8d0Jason Sams    Element mElement_MATRIX_2X2;
8911d45c47975ab2a8cef6db5a8976276de31e1e8d0Jason Sams
8924d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    Sampler mSampler_CLAMP_NEAREST;
8934d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    Sampler mSampler_CLAMP_LINEAR;
8944d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    Sampler mSampler_CLAMP_LINEAR_MIP_LINEAR;
8954d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    Sampler mSampler_WRAP_NEAREST;
8964d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    Sampler mSampler_WRAP_LINEAR;
8974d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    Sampler mSampler_WRAP_LINEAR_MIP_LINEAR;
8986b9b2caf2bf977508e223792bb5eba75091c232dTim Murray    Sampler mSampler_MIRRORED_REPEAT_NEAREST;
8996b9b2caf2bf977508e223792bb5eba75091c232dTim Murray    Sampler mSampler_MIRRORED_REPEAT_LINEAR;
9006b9b2caf2bf977508e223792bb5eba75091c232dTim Murray    Sampler mSampler_MIRRORED_REPEAT_LINEAR_MIP_LINEAR;
9014d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams
902d36f248eaf06c569010649902df653da1a9e2accAlex Sakhartchouk    ProgramStore mProgramStore_BLEND_NONE_DEPTH_TEST;
903d36f248eaf06c569010649902df653da1a9e2accAlex Sakhartchouk    ProgramStore mProgramStore_BLEND_NONE_DEPTH_NO_DEPTH;
904d36f248eaf06c569010649902df653da1a9e2accAlex Sakhartchouk    ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_TEST;
905d36f248eaf06c569010649902df653da1a9e2accAlex Sakhartchouk    ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_NO_DEPTH;
906d36f248eaf06c569010649902df653da1a9e2accAlex Sakhartchouk
907d36f248eaf06c569010649902df653da1a9e2accAlex Sakhartchouk    ProgramRaster mProgramRaster_CULL_BACK;
908d36f248eaf06c569010649902df653da1a9e2accAlex Sakhartchouk    ProgramRaster mProgramRaster_CULL_FRONT;
909d36f248eaf06c569010649902df653da1a9e2accAlex Sakhartchouk    ProgramRaster mProgramRaster_CULL_NONE;
91032e09b5891da0174f161d99e2d3ebe67d6efa39cAlex Sakhartchouk
91160aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich    ///////////////////////////////////////////////////////////////////////////////////
91243702d8925c54360ad5f9f66b0d35d61d59f6910Jack Palevich    //
91360aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
9149c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines    /**
91527676fe24be7444a174c15df476e49adc5335d03Jason Sams     * Base class application should derive from for handling RS messages
9168cecbb5293f73e3f63f2601dda68016762c58a0cStephen Hines     * coming from their scripts.  When a script calls sendToClient the data
91727676fe24be7444a174c15df476e49adc5335d03Jason Sams     * fields will be filled in and then the run method called by a message
91827676fe24be7444a174c15df476e49adc5335d03Jason Sams     * handling thread.  This will occur some time after sendToClient completes
91927676fe24be7444a174c15df476e49adc5335d03Jason Sams     * in the script.
92027676fe24be7444a174c15df476e49adc5335d03Jason Sams     *
92127676fe24be7444a174c15df476e49adc5335d03Jason Sams     */
922bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    public static class RSMessageHandler implements Runnable {
923516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        protected int[] mData;
924516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        protected int mID;
9251c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams        protected int mLength;
926516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        public void run() {
927516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        }
928516c31911578db8ce53529483c3ded918ac7dc6bJason Sams    }
9299c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines    /**
93027676fe24be7444a174c15df476e49adc5335d03Jason Sams     * If an application is expecting messages it should set this field to an
93127676fe24be7444a174c15df476e49adc5335d03Jason Sams     * instance of RSMessage.  This instance will receive all the user messages
93227676fe24be7444a174c15df476e49adc5335d03Jason Sams     * sent from sendToClient by scripts from this context.
93327676fe24be7444a174c15df476e49adc5335d03Jason Sams     *
93427676fe24be7444a174c15df476e49adc5335d03Jason Sams     */
935bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    RSMessageHandler mMessageCallback = null;
936bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams
937bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    public void setMessageHandler(RSMessageHandler msg) {
938bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams        mMessageCallback = msg;
939bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    }
940bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    public RSMessageHandler getMessageHandler() {
941bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams        return mMessageCallback;
942bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    }
943516c31911578db8ce53529483c3ded918ac7dc6bJason Sams
9449c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines    /**
94502d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams     * Place a message into the message queue to be sent back to the message
94602d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams     * handler once all previous commands have been executed.
947455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams     *
948455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams     * @param id
949455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams     * @param data
950455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams     */
951455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams    public void sendMessage(int id, int[] data) {
952455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams        nContextSendMessage(id, data);
953455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams    }
954455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams
955455d64426615e5d269a3bd05cd91b67c3811fcdfJason Sams    /**
95627676fe24be7444a174c15df476e49adc5335d03Jason Sams     * Runtime error base class.  An application should derive from this class
95727676fe24be7444a174c15df476e49adc5335d03Jason Sams     * if it wishes to install an error handler.  When errors occur at runtime
95827676fe24be7444a174c15df476e49adc5335d03Jason Sams     * the fields in this class will be filled and the run method called.
95927676fe24be7444a174c15df476e49adc5335d03Jason Sams     *
96027676fe24be7444a174c15df476e49adc5335d03Jason Sams     */
961bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    public static class RSErrorHandler implements Runnable {
9621c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams        protected String mErrorMessage;
9631c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams        protected int mErrorNum;
9641c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams        public void run() {
9651c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams        }
9661c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams    }
96727676fe24be7444a174c15df476e49adc5335d03Jason Sams
9689c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines    /**
96927676fe24be7444a174c15df476e49adc5335d03Jason Sams     * Application Error handler.  All runtime errors will be dispatched to the
97027676fe24be7444a174c15df476e49adc5335d03Jason Sams     * instance of RSAsyncError set here.  If this field is null a
97127676fe24be7444a174c15df476e49adc5335d03Jason Sams     * RSRuntimeException will instead be thrown with details about the error.
97227676fe24be7444a174c15df476e49adc5335d03Jason Sams     * This will cause program termaination.
97327676fe24be7444a174c15df476e49adc5335d03Jason Sams     *
97427676fe24be7444a174c15df476e49adc5335d03Jason Sams     */
975bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    RSErrorHandler mErrorCallback = null;
976bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams
977bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    public void setErrorHandler(RSErrorHandler msg) {
978bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams        mErrorCallback = msg;
979bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    }
980bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    public RSErrorHandler getErrorHandler() {
981bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams        return mErrorCallback;
982bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    }
9831c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams
9849c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines    /**
98527676fe24be7444a174c15df476e49adc5335d03Jason Sams     * RenderScript worker threads priority enumeration.  The default value is
98627676fe24be7444a174c15df476e49adc5335d03Jason Sams     * NORMAL.  Applications wishing to do background processing such as
98727676fe24be7444a174c15df476e49adc5335d03Jason Sams     * wallpapers should set their priority to LOW to avoid starving forground
98827676fe24be7444a174c15df476e49adc5335d03Jason Sams     * processes.
98927676fe24be7444a174c15df476e49adc5335d03Jason Sams     */
9907d787b4722eaeb79cab42c36060336e092b77b5fJason Sams    public enum Priority {
991260c77a4f741c3db76057cc4ea2ee54fe335ecf9Glenn Kasten        LOW (Process.THREAD_PRIORITY_BACKGROUND + (5 * Process.THREAD_PRIORITY_LESS_FAVORABLE)),
992260c77a4f741c3db76057cc4ea2ee54fe335ecf9Glenn Kasten        NORMAL (Process.THREAD_PRIORITY_DISPLAY);
9937d787b4722eaeb79cab42c36060336e092b77b5fJason Sams
9947d787b4722eaeb79cab42c36060336e092b77b5fJason Sams        int mID;
9957d787b4722eaeb79cab42c36060336e092b77b5fJason Sams        Priority(int id) {
9967d787b4722eaeb79cab42c36060336e092b77b5fJason Sams            mID = id;
9977d787b4722eaeb79cab42c36060336e092b77b5fJason Sams        }
9987d787b4722eaeb79cab42c36060336e092b77b5fJason Sams    }
9997d787b4722eaeb79cab42c36060336e092b77b5fJason Sams
1000771bebb94054d06f97284379c93a2620613513c3Jason Sams    void validate() {
1001771bebb94054d06f97284379c93a2620613513c3Jason Sams        if (mContext == 0) {
1002c1d6210fb5cc558ccea95a59a2b33bb9015fc7deJason Sams            throw new RSInvalidStateException("Calling RS with no Context active.");
1003771bebb94054d06f97284379c93a2620613513c3Jason Sams        }
1004771bebb94054d06f97284379c93a2620613513c3Jason Sams    }
1005771bebb94054d06f97284379c93a2620613513c3Jason Sams
100627676fe24be7444a174c15df476e49adc5335d03Jason Sams
10079c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines    /**
100827676fe24be7444a174c15df476e49adc5335d03Jason Sams     * Change the priority of the worker threads for this context.
100927676fe24be7444a174c15df476e49adc5335d03Jason Sams     *
101027676fe24be7444a174c15df476e49adc5335d03Jason Sams     * @param p New priority to be set.
101127676fe24be7444a174c15df476e49adc5335d03Jason Sams     */
1012bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    public void setPriority(Priority p) {
10135dbfe93b3f15f3a837836d024958635fd8f9ad14Jason Sams        validate();
10147d787b4722eaeb79cab42c36060336e092b77b5fJason Sams        nContextSetPriority(p.mID);
10157d787b4722eaeb79cab42c36060336e092b77b5fJason Sams    }
10167d787b4722eaeb79cab42c36060336e092b77b5fJason Sams
1017bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    static class MessageThread extends Thread {
1018516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        RenderScript mRS;
1019516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        boolean mRun = true;
1020bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams        int[] mAuxData = new int[2];
10211c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams
1022bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams        static final int RS_MESSAGE_TO_CLIENT_NONE = 0;
1023bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams        static final int RS_MESSAGE_TO_CLIENT_EXCEPTION = 1;
1024bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams        static final int RS_MESSAGE_TO_CLIENT_RESIZE = 2;
1025bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams        static final int RS_MESSAGE_TO_CLIENT_ERROR = 3;
1026bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams        static final int RS_MESSAGE_TO_CLIENT_USER = 4;
1027739c8263a10d34f5acba7fce2052012d1545d10bJason Sams        static final int RS_MESSAGE_TO_CLIENT_NEW_BUFFER = 5;
1028516c31911578db8ce53529483c3ded918ac7dc6bJason Sams
102942028a87568c2b7b5ff3691df7c345bbc5802adeStephen Hines        static final int RS_ERROR_FATAL_DEBUG = 0x0800;
1030bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams        static final int RS_ERROR_FATAL_UNKNOWN = 0x1000;
1031add9d9633205f76cc34f04368b8482c2c369ba63Jason Sams
1032516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        MessageThread(RenderScript rs) {
1033516c31911578db8ce53529483c3ded918ac7dc6bJason Sams            super("RSMessageThread");
1034516c31911578db8ce53529483c3ded918ac7dc6bJason Sams            mRS = rs;
1035516c31911578db8ce53529483c3ded918ac7dc6bJason Sams
1036516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        }
1037516c31911578db8ce53529483c3ded918ac7dc6bJason Sams
1038516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        public void run() {
1039516c31911578db8ce53529483c3ded918ac7dc6bJason Sams            // This function is a temporary solution.  The final solution will
1040516c31911578db8ce53529483c3ded918ac7dc6bJason Sams            // used typed allocations where the message id is the type indicator.
1041516c31911578db8ce53529483c3ded918ac7dc6bJason Sams            int[] rbuf = new int[16];
10422e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams            mRS.nContextInitToClient(mRS.mContext);
1043516c31911578db8ce53529483c3ded918ac7dc6bJason Sams            while(mRun) {
10441d45c47975ab2a8cef6db5a8976276de31e1e8d0Jason Sams                rbuf[0] = 0;
1045edbfabdb98a2974f973d6c042e6efd547dc02fc5Jason Sams                int msg = mRS.nContextPeekMessage(mRS.mContext, mAuxData);
1046bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams                int size = mAuxData[1];
1047bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams                int subID = mAuxData[0];
10481c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams
10491c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                if (msg == RS_MESSAGE_TO_CLIENT_USER) {
10501c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                    if ((size>>2) >= rbuf.length) {
10511c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                        rbuf = new int[(size + 3) >> 2];
10521c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                    }
1053edbfabdb98a2974f973d6c042e6efd547dc02fc5Jason Sams                    if (mRS.nContextGetUserMessage(mRS.mContext, rbuf) !=
1054edbfabdb98a2974f973d6c042e6efd547dc02fc5Jason Sams                        RS_MESSAGE_TO_CLIENT_USER) {
1055edbfabdb98a2974f973d6c042e6efd547dc02fc5Jason Sams                        throw new RSDriverException("Error processing message from Renderscript.");
1056edbfabdb98a2974f973d6c042e6efd547dc02fc5Jason Sams                    }
10571c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams
10581c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                    if(mRS.mMessageCallback != null) {
10591c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                        mRS.mMessageCallback.mData = rbuf;
10601c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                        mRS.mMessageCallback.mID = subID;
10611c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                        mRS.mMessageCallback.mLength = size;
10621c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                        mRS.mMessageCallback.run();
10631d45c47975ab2a8cef6db5a8976276de31e1e8d0Jason Sams                    } else {
10641c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                        throw new RSInvalidStateException("Received a message from the script with no message handler installed.");
1065516c31911578db8ce53529483c3ded918ac7dc6bJason Sams                    }
1066ab98bb6e8b95bef7415c1ad239be71f93322fbadStephen Hines                    continue;
1067516c31911578db8ce53529483c3ded918ac7dc6bJason Sams                }
10681c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams
10691c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                if (msg == RS_MESSAGE_TO_CLIENT_ERROR) {
10701c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                    String e = mRS.nContextGetErrorMessage(mRS.mContext);
10711c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams
107242028a87568c2b7b5ff3691df7c345bbc5802adeStephen Hines                    // Throw RSRuntimeException under the following conditions:
107342028a87568c2b7b5ff3691df7c345bbc5802adeStephen Hines                    //
107442028a87568c2b7b5ff3691df7c345bbc5802adeStephen Hines                    // 1) It is an unknown fatal error.
107542028a87568c2b7b5ff3691df7c345bbc5802adeStephen Hines                    // 2) It is a debug fatal error, and we are not in a
107642028a87568c2b7b5ff3691df7c345bbc5802adeStephen Hines                    //    debug context.
107742028a87568c2b7b5ff3691df7c345bbc5802adeStephen Hines                    // 3) It is a debug fatal error, and we do not have an
107842028a87568c2b7b5ff3691df7c345bbc5802adeStephen Hines                    //    error callback.
107942028a87568c2b7b5ff3691df7c345bbc5802adeStephen Hines                    if (subID >= RS_ERROR_FATAL_UNKNOWN ||
108042028a87568c2b7b5ff3691df7c345bbc5802adeStephen Hines                        (subID >= RS_ERROR_FATAL_DEBUG &&
108142028a87568c2b7b5ff3691df7c345bbc5802adeStephen Hines                         (mRS.mContextType != ContextType.DEBUG ||
108242028a87568c2b7b5ff3691df7c345bbc5802adeStephen Hines                          mRS.mErrorCallback == null))) {
1083add9d9633205f76cc34f04368b8482c2c369ba63Jason Sams                        throw new RSRuntimeException("Fatal error " + subID + ", details: " + e);
1084add9d9633205f76cc34f04368b8482c2c369ba63Jason Sams                    }
1085add9d9633205f76cc34f04368b8482c2c369ba63Jason Sams
10861c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                    if(mRS.mErrorCallback != null) {
10871c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                        mRS.mErrorCallback.mErrorMessage = e;
10881c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                        mRS.mErrorCallback.mErrorNum = subID;
10891c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                        mRS.mErrorCallback.run();
10901c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                    } else {
1091a4b7bc97862e01d38b483524f1d1cf433d29e294Jason Sams                        android.util.Log.e(LOG_TAG, "non fatal RS error, " + e);
1092be74bdd2349095f203ae0fddcc4816bfbd56bc5dStephen Hines                        // Do not throw here. In these cases, we do not have
1093be74bdd2349095f203ae0fddcc4816bfbd56bc5dStephen Hines                        // a fatal error.
10941c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                    }
10951c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                    continue;
10961c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                }
10971c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams
1098739c8263a10d34f5acba7fce2052012d1545d10bJason Sams                if (msg == RS_MESSAGE_TO_CLIENT_NEW_BUFFER) {
1099739c8263a10d34f5acba7fce2052012d1545d10bJason Sams                    Allocation.sendBufferNotification(subID);
1100739c8263a10d34f5acba7fce2052012d1545d10bJason Sams                    continue;
1101739c8263a10d34f5acba7fce2052012d1545d10bJason Sams                }
1102739c8263a10d34f5acba7fce2052012d1545d10bJason Sams
11031c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                // 2: teardown.
11041c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                // But we want to avoid starving other threads during
11051c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                // teardown by yielding until the next line in the destructor
11061c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                // can execute to set mRun = false
11071c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                try {
11081c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                    sleep(1, 0);
11091c41517124a90fcfdb95dc069fc492c6fcf1ff25Jason Sams                } catch(InterruptedException e) {
1110516c31911578db8ce53529483c3ded918ac7dc6bJason Sams                }
1111516c31911578db8ce53529483c3ded918ac7dc6bJason Sams            }
1112da67debe22159fdf0bbeca6340766ebe2b8e67a3Tim Murray            //Log.d(LOG_TAG, "MessageThread exiting.");
1113516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        }
1114516c31911578db8ce53529483c3ded918ac7dc6bJason Sams    }
1115516c31911578db8ce53529483c3ded918ac7dc6bJason Sams
11166b32fab1dbfd8bc1cc176557fe0a7b2ebd4966bdShih-wei Liao    RenderScript(Context ctx) {
111742028a87568c2b7b5ff3691df7c345bbc5802adeStephen Hines        mContextType = ContextType.NORMAL;
11181a4e1f3efd077f3a61038aedab84dc84c9c44d19Jason Sams        if (ctx != null) {
11191a4e1f3efd077f3a61038aedab84dc84c9c44d19Jason Sams            mApplicationContext = ctx.getApplicationContext();
11201a4e1f3efd077f3a61038aedab84dc84c9c44d19Jason Sams        }
112160aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich    }
112260aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
11239c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines    /**
11246b32fab1dbfd8bc1cc176557fe0a7b2ebd4966bdShih-wei Liao     * Gets the application context associated with the RenderScript context.
112527676fe24be7444a174c15df476e49adc5335d03Jason Sams     *
11266b32fab1dbfd8bc1cc176557fe0a7b2ebd4966bdShih-wei Liao     * @return The application context.
11276b32fab1dbfd8bc1cc176557fe0a7b2ebd4966bdShih-wei Liao     */
11286b32fab1dbfd8bc1cc176557fe0a7b2ebd4966bdShih-wei Liao    public final Context getApplicationContext() {
11296b32fab1dbfd8bc1cc176557fe0a7b2ebd4966bdShih-wei Liao        return mApplicationContext;
11306b32fab1dbfd8bc1cc176557fe0a7b2ebd4966bdShih-wei Liao    }
11316b32fab1dbfd8bc1cc176557fe0a7b2ebd4966bdShih-wei Liao
11329c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines    /**
1133add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams     * @hide
1134add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams     */
1135add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams    public static RenderScript create(Context ctx, int sdkVersion) {
1136add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams        return create(ctx, sdkVersion, ContextType.NORMAL);
1137add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams    }
1138add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams
1139add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams    /**
11406b32fab1dbfd8bc1cc176557fe0a7b2ebd4966bdShih-wei Liao     * Create a basic RenderScript context.
114127676fe24be7444a174c15df476e49adc5335d03Jason Sams     *
11421a4e1f3efd077f3a61038aedab84dc84c9c44d19Jason Sams     * @hide
11436b32fab1dbfd8bc1cc176557fe0a7b2ebd4966bdShih-wei Liao     * @param ctx The context.
114427676fe24be7444a174c15df476e49adc5335d03Jason Sams     * @return RenderScript
114527676fe24be7444a174c15df476e49adc5335d03Jason Sams     */
1146add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams    public static RenderScript create(Context ctx, int sdkVersion, ContextType ct) {
1147e4d9a01bfc7451afff1ed399a5801c7aa2af2831Dan Morrill        if (!sInitialized) {
1148e4d9a01bfc7451afff1ed399a5801c7aa2af2831Dan Morrill            Log.e(LOG_TAG, "RenderScript.create() called when disabled; someone is likely to crash");
1149e4d9a01bfc7451afff1ed399a5801c7aa2af2831Dan Morrill            return null;
1150e4d9a01bfc7451afff1ed399a5801c7aa2af2831Dan Morrill        }
1151e4d9a01bfc7451afff1ed399a5801c7aa2af2831Dan Morrill
11526b32fab1dbfd8bc1cc176557fe0a7b2ebd4966bdShih-wei Liao        RenderScript rs = new RenderScript(ctx);
1153704ff64b099406bb328898a7443921f22dbffd6dJason Sams
1154704ff64b099406bb328898a7443921f22dbffd6dJason Sams        rs.mDev = rs.nDeviceCreate();
1155add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams        rs.mContext = rs.nContextCreate(rs.mDev, 0, sdkVersion, ct.mID);
115642028a87568c2b7b5ff3691df7c345bbc5802adeStephen Hines        rs.mContextType = ct;
11572698536b3ff60bfee85e47e4a8d4b25fdfdf4db5Jason Sams        if (rs.mContext == 0) {
11582698536b3ff60bfee85e47e4a8d4b25fdfdf4db5Jason Sams            throw new RSDriverException("Failed to create RS context.");
11592698536b3ff60bfee85e47e4a8d4b25fdfdf4db5Jason Sams        }
1160704ff64b099406bb328898a7443921f22dbffd6dJason Sams        rs.mMessageThread = new MessageThread(rs);
1161704ff64b099406bb328898a7443921f22dbffd6dJason Sams        rs.mMessageThread.start();
1162704ff64b099406bb328898a7443921f22dbffd6dJason Sams        return rs;
1163efd9b6fb2e0f31b50db089352118e5daeb268879Jason Sams    }
1164efd9b6fb2e0f31b50db089352118e5daeb268879Jason Sams
11659c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines    /**
11661a4e1f3efd077f3a61038aedab84dc84c9c44d19Jason Sams     * Create a basic RenderScript context.
11671a4e1f3efd077f3a61038aedab84dc84c9c44d19Jason Sams     *
11681a4e1f3efd077f3a61038aedab84dc84c9c44d19Jason Sams     * @param ctx The context.
11691a4e1f3efd077f3a61038aedab84dc84c9c44d19Jason Sams     * @return RenderScript
11701a4e1f3efd077f3a61038aedab84dc84c9c44d19Jason Sams     */
11711a4e1f3efd077f3a61038aedab84dc84c9c44d19Jason Sams    public static RenderScript create(Context ctx) {
1172add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams        return create(ctx, ContextType.NORMAL);
1173add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams    }
1174add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams
1175add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams    /**
1176add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams     * Create a basic RenderScript context.
1177add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams     *
1178add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams     *
1179add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams     * @param ctx The context.
118002d56d90e01e20db8424de94a14fe59dc94f19c0Jason Sams     * @param ct The type of context to be created.
1181add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams     * @return RenderScript
1182add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams     */
1183add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams    public static RenderScript create(Context ctx, ContextType ct) {
11841a4e1f3efd077f3a61038aedab84dc84c9c44d19Jason Sams        int v = ctx.getApplicationInfo().targetSdkVersion;
1185add26dca07cc5a5c935bc68f57bee2c1cd96a79eJason Sams        return create(ctx, v, ct);
11861a4e1f3efd077f3a61038aedab84dc84c9c44d19Jason Sams    }
11871a4e1f3efd077f3a61038aedab84dc84c9c44d19Jason Sams
11889c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines    /**
118927676fe24be7444a174c15df476e49adc5335d03Jason Sams     * Print the currently available debugging information about the state of
119027676fe24be7444a174c15df476e49adc5335d03Jason Sams     * the RS context to the log.
119127676fe24be7444a174c15df476e49adc5335d03Jason Sams     *
119227676fe24be7444a174c15df476e49adc5335d03Jason Sams     */
1193bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    public void contextDump() {
11945dbfe93b3f15f3a837836d024958635fd8f9ad14Jason Sams        validate();
1195bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams        nContextDump(0);
1196715333b832fb448c32165c7d97d408a3fa43f7cbJason Sams    }
1197715333b832fb448c32165c7d97d408a3fa43f7cbJason Sams
11989c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines    /**
119927676fe24be7444a174c15df476e49adc5335d03Jason Sams     * Wait for any commands in the fifo between the java bindings and native to
120027676fe24be7444a174c15df476e49adc5335d03Jason Sams     * be processed.
120127676fe24be7444a174c15df476e49adc5335d03Jason Sams     *
120227676fe24be7444a174c15df476e49adc5335d03Jason Sams     */
120396ed4cfa62dd09aafb3f9da01e047661b4fe3c95Jason Sams    public void finish() {
120496ed4cfa62dd09aafb3f9da01e047661b4fe3c95Jason Sams        nContextFinish();
120596ed4cfa62dd09aafb3f9da01e047661b4fe3c95Jason Sams    }
120696ed4cfa62dd09aafb3f9da01e047661b4fe3c95Jason Sams
12079c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines    /**
120827676fe24be7444a174c15df476e49adc5335d03Jason Sams     * Destroy this renderscript context.  Once this function is called its no
120927676fe24be7444a174c15df476e49adc5335d03Jason Sams     * longer legal to use this or any objects created by this context.
121027676fe24be7444a174c15df476e49adc5335d03Jason Sams     *
121127676fe24be7444a174c15df476e49adc5335d03Jason Sams     */
1212f5b4596a383b6ab83f92edecfe054e80b555c2d0Jason Sams    public void destroy() {
12135dbfe93b3f15f3a837836d024958635fd8f9ad14Jason Sams        validate();
12142e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        nContextDeinitToClient(mContext);
1215516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        mMessageThread.mRun = false;
1216a8bf9429b29743b3489817feb21bde2416acc465Jason Sams        try {
1217a8bf9429b29743b3489817feb21bde2416acc465Jason Sams            mMessageThread.join();
1218a8bf9429b29743b3489817feb21bde2416acc465Jason Sams        } catch(InterruptedException e) {
1219a8bf9429b29743b3489817feb21bde2416acc465Jason Sams        }
1220516c31911578db8ce53529483c3ded918ac7dc6bJason Sams
12212e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        nContextDestroy();
1222f5b4596a383b6ab83f92edecfe054e80b555c2d0Jason Sams        mContext = 0;
1223f5b4596a383b6ab83f92edecfe054e80b555c2d0Jason Sams
1224f5b4596a383b6ab83f92edecfe054e80b555c2d0Jason Sams        nDeviceDestroy(mDev);
1225f5b4596a383b6ab83f92edecfe054e80b555c2d0Jason Sams        mDev = 0;
1226f5b4596a383b6ab83f92edecfe054e80b555c2d0Jason Sams    }
122702fb2cb531035779a25dbf9595e0628ea40585b0Jason Sams
1228a9e7a05b84470257637c97d65f6562aa832c66efJason Sams    boolean isAlive() {
1229a9e7a05b84470257637c97d65f6562aa832c66efJason Sams        return mContext != 0;
1230a9e7a05b84470257637c97d65f6562aa832c66efJason Sams    }
1231a9e7a05b84470257637c97d65f6562aa832c66efJason Sams
1232bf6ef8d78fffbce6c1849a4a28fb3f4401ad039eJason Sams    int safeID(BaseObj o) {
12336b9dec00afec359f091ed353f371f08ff150278aJason Sams        if(o != null) {
1234e07694b24f7d12d72b084b6651356681ebd0efd6Jason Sams            return o.getID(this);
1235d8e4161f114331343b897cbacea927e7e60e7b17Jason Sams        }
12366b9dec00afec359f091ed353f371f08ff150278aJason Sams        return 0;
123760aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich    }
123860aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich}
1239