RenderScript.java revision 2e1872fe07cf8952812a417985e6e1f61bdeab5d
160aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich/*
260aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich * Copyright (C) 2008 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
1943ee06857bb7f99446d1d84f8789016c5d105558Jason Samsimport java.lang.reflect.Field;
2036e612a488511940b61f09803b270aa1c61b68e0Jason Sams
21b8c5a84e7c23746a3fc26013e0880d3d95ca6588Jason Samsimport android.graphics.Bitmap;
22650a3eb7d621dc8e81573142a4498bbd07bcde27Romain Guyimport android.graphics.BitmapFactory;
2336e612a488511940b61f09803b270aa1c61b68e0Jason Samsimport android.util.Config;
2436e612a488511940b61f09803b270aa1c61b68e0Jason Samsimport android.util.Log;
2536e612a488511940b61f09803b270aa1c61b68e0Jason Samsimport android.view.Surface;
2643702d8925c54360ad5f9f66b0d35d61d59f6910Jack Palevich
2760aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
28e29d471e5ca9781d8772d445ec7832e94856fd14Jason Sams/**
29e29d471e5ca9781d8772d445ec7832e94856fd14Jason Sams * @hide
30e29d471e5ca9781d8772d445ec7832e94856fd14Jason Sams *
31e29d471e5ca9781d8772d445ec7832e94856fd14Jason Sams **/
3260aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevichpublic class RenderScript {
333bc47d438171dce294e816366d53bc9eca772c5bJason Sams    static final String LOG_TAG = "RenderScript_jni";
34704ff64b099406bb328898a7443921f22dbffd6dJason Sams    protected static final boolean DEBUG  = false;
35650a3eb7d621dc8e81573142a4498bbd07bcde27Romain Guy    @SuppressWarnings({"UnusedDeclaration", "deprecation"})
36704ff64b099406bb328898a7443921f22dbffd6dJason Sams    protected static final boolean LOG_ENABLED = DEBUG ? Config.LOGD : Config.LOGV;
3760aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
3860aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
3960aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
4002fb2cb531035779a25dbf9595e0628ea40585b0Jason Sams     /*
4160aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich     * We use a class initializer to allow the native code to cache some
4260aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich     * field offsets.
4360aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich     */
44650a3eb7d621dc8e81573142a4498bbd07bcde27Romain Guy    @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"})
45704ff64b099406bb328898a7443921f22dbffd6dJason Sams    protected static boolean sInitialized;
46704ff64b099406bb328898a7443921f22dbffd6dJason Sams    native protected static void _nInit();
4760aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
48dba3ba5b5bf6026abceced921b1b0d231b0faefdJason Sams
4960aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich    static {
5060aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich        sInitialized = false;
5160aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich        try {
52e29d471e5ca9781d8772d445ec7832e94856fd14Jason Sams            System.loadLibrary("rs_jni");
5360aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich            _nInit();
5460aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich            sInitialized = true;
5560aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich        } catch (UnsatisfiedLinkError e) {
5660aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich            Log.d(LOG_TAG, "RenderScript JNI library not found!");
5760aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich        }
5860aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich    }
5960aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
602e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    // Non-threadsafe functions.
61ea84a7c51790f9ba5f2194a66d6cf4ea8d879776Jason Sams    native void nInitElements(int a8, int rgba4444, int rgba8888, int rgb565);
6236e612a488511940b61f09803b270aa1c61b68e0Jason Sams    native int  nDeviceCreate();
6336e612a488511940b61f09803b270aa1c61b68e0Jason Sams    native void nDeviceDestroy(int dev);
64ebfb436a49673693b98469683451bd9ede797557Jason Sams    native void nDeviceSetConfig(int dev, int param, int value);
652e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  nContextGetMessage(int con, int[] data, boolean wait);
662e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void nContextInitToClient(int con);
672e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void nContextDeinitToClient(int con);
682e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
692e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
702e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    // Methods below are wrapped to protect the non-threadsafe
712e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    // lockless fifo.
722e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnContextCreateGL(int dev, int ver, boolean useDepth);
732e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nContextCreateGL(int dev, int ver, boolean useDepth) {
742e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnContextCreateGL(dev, ver, useDepth);
752e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
762e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnContextCreate(int dev, int ver);
772e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nContextCreate(int dev, int ver) {
782e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnContextCreate(dev, ver);
792e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
802e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextDestroy(int con);
812e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextDestroy() {
822e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextDestroy(mContext);
832e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
842e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextSetSurface(int con, int w, int h, Surface sur);
852e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextSetSurface(int w, int h, Surface sur) {
862e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextSetSurface(mContext, w, h, sur);
872e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
882e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextSetPriority(int con, int p);
892e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextSetPriority(int p) {
902e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextSetPriority(mContext, p);
912e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
922e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextDump(int con, int bits);
932e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextDump(int bits) {
942e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextDump(mContext, bits);
952e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
962e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextFinish(int con);
972e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextFinish() {
982e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextFinish(mContext);
992e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1002e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
1012e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextBindRootScript(int con, int script);
1022e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextBindRootScript(int script) {
1032e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextBindRootScript(mContext, script);
1042e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1052e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextBindSampler(int con, int sampler, int slot);
1062e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextBindSampler(int sampler, int slot) {
1072e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextBindSampler(mContext, sampler, slot);
1082e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1092e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextBindProgramStore(int con, int pfs);
1102e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextBindProgramStore(int pfs) {
1112e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextBindProgramStore(mContext, pfs);
1122e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1132e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextBindProgramFragment(int con, int pf);
1142e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextBindProgramFragment(int pf) {
1152e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextBindProgramFragment(mContext, pf);
1162e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1172e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextBindProgramVertex(int con, int pv);
1182e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextBindProgramVertex(int pv) {
1192e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextBindProgramVertex(mContext, pv);
1202e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1212e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextBindProgramRaster(int con, int pr);
1222e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextBindProgramRaster(int pr) {
1232e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextBindProgramRaster(mContext, pr);
1242e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1252e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextPause(int con);
1262e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextPause() {
1272e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextPause(mContext);
1282e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1292e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnContextResume(int con);
1302e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nContextResume() {
1312e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnContextResume(mContext);
1322e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1332e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
1342e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAssignName(int con, int obj, byte[] name);
1352e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAssignName(int obj, byte[] name) {
1362e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAssignName(mContext, obj, name);
1372e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1382e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native String rsnGetName(int con, int obj);
1392e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized String nGetName(int obj) {
1402e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnGetName(mContext, obj);
1412e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1422e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnObjDestroy(int con, int id);
1432e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nObjDestroy(int id) {
1442e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnObjDestroy(mContext, id);
1452e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1462e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnObjDestroyOOB(int con, int id);
1472e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nObjDestroyOOB(int id) {
1482e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnObjDestroyOOB(mContext, id);
1492e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1502e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnFileOpen(int con, byte[] name);
1512e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nFileOpen(byte[] name) {
1522e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnFileOpen(mContext, name);
1532e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1542e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
1552e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnElementCreate(int con, int type, int kind, boolean norm, int vecSize);
1562e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nElementCreate(int type, int kind, boolean norm, int vecSize) {
1572e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnElementCreate(mContext, type, kind, norm, vecSize);
1582e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1592e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnElementCreate2(int con, int[] elements, String[] names);
1602e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nElementCreate2(int[] elements, String[] names) {
1612e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnElementCreate2(mContext, elements, names);
1622e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1632e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnElementGetNativeData(int con, int id, int[] elementData);
1642e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nElementGetNativeData(int id, int[] elementData) {
1652e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnElementGetNativeData(mContext, id, elementData);
1662e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1672e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnElementGetSubElements(int con, int id, int[] IDs, String[] names);
1682e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nElementGetSubElements(int id, int[] IDs, String[] names) {
1692e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnElementGetSubElements(mContext, id, IDs, names);
1702e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1712e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
1722e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnTypeBegin(int con, int elementID);
1732e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nTypeBegin(int elementID) {
1742e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnTypeBegin(mContext, elementID);
1752e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1762e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnTypeAdd(int con, int dim, int val);
1772e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nTypeAdd(int dim, int val) {
1782e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnTypeAdd(mContext, dim, val);
1792e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1802e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnTypeCreate(int con);
1812e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nTypeCreate() {
1822e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnTypeCreate(mContext);
1832e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1842e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnTypeFinalDestroy(int con, Type t);
1852e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nTypeFinalDestroy(Type t) {
1862e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnTypeFinalDestroy(mContext, t);
1872e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1882e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnTypeSetupFields(int con, Type t, int[] types, int[] bits, Field[] IDs);
1892e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nTypeSetupFields(Type t, int[] types, int[] bits, Field[] IDs) {
1902e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnTypeSetupFields(mContext, t, types, bits, IDs);
1912e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1922e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnTypeGetNativeData(int con, int id, int[] typeData);
1932e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nTypeGetNativeData(int id, int[] typeData) {
1942e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnTypeGetNativeData(mContext, id, typeData);
1952e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1962e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
1972e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnAllocationCreateTyped(int con, int type);
1982e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nAllocationCreateTyped(int type) {
1992e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnAllocationCreateTyped(mContext, type);
2002e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2012e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnAllocationCreateFromBitmap(int con, int dstFmt, boolean genMips, Bitmap bmp);
2022e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nAllocationCreateFromBitmap(int dstFmt, boolean genMips, Bitmap bmp) {
2032e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnAllocationCreateFromBitmap(mContext, dstFmt, genMips, bmp);
2042e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2052e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnAllocationCreateBitmapRef(int con, int type, Bitmap bmp);
2062e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nAllocationCreateBitmapRef(int type, Bitmap bmp) {
2072e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnAllocationCreateBitmapRef(mContext, type, bmp);
2082e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2092e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnAllocationCreateFromBitmapBoxed(int con, int dstFmt, boolean genMips, Bitmap bmp);
2102e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nAllocationCreateFromBitmapBoxed(int dstFmt, boolean genMips, Bitmap bmp) {
2112e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnAllocationCreateFromBitmapBoxed(mContext, dstFmt, genMips, bmp);
2122e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2132e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnAllocationCreateFromAssetStream(int con, int dstFmt, boolean genMips, int assetStream);
2142e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nAllocationCreateFromAssetStream(int dstFmt, boolean genMips, int assetStream) {
2152e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnAllocationCreateFromAssetStream(mContext, dstFmt, genMips, assetStream);
2162e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2172e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
2182e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAllocationUploadToTexture(int con, int alloc, boolean genMips, int baseMioLevel);
2192e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAllocationUploadToTexture(int alloc, boolean genMips, int baseMioLevel) {
2202e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAllocationUploadToTexture(mContext, alloc, genMips, baseMioLevel);
2212e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2222e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAllocationUploadToBufferObject(int con, int alloc);
2232e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAllocationUploadToBufferObject(int alloc) {
2242e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAllocationUploadToBufferObject(mContext, alloc);
2252e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2262e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
2272e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAllocationSubData1D(int con, int id, int off, int count, int[] d, int sizeBytes);
2282e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAllocationSubData1D(int id, int off, int count, int[] d, int sizeBytes) {
2292e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAllocationSubData1D(mContext, id, off, count, d, sizeBytes);
2302e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2312e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAllocationSubData1D(int con, int id, int off, int count, short[] d, int sizeBytes);
2322e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAllocationSubData1D(int id, int off, int count, short[] d, int sizeBytes) {
2332e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAllocationSubData1D(mContext, id, off, count, d, sizeBytes);
2342e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2352e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAllocationSubData1D(int con, int id, int off, int count, byte[] d, int sizeBytes);
2362e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAllocationSubData1D(int id, int off, int count, byte[] d, int sizeBytes) {
2372e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAllocationSubData1D(mContext, id, off, count, d, sizeBytes);
2382e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2392e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAllocationSubData1D(int con, int id, int off, int count, float[] d, int sizeBytes);
2402e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAllocationSubData1D(int id, int off, int count, float[] d, int sizeBytes) {
2412e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAllocationSubData1D(mContext, id, off, count, d, sizeBytes);
2422e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2432e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
2442e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAllocationSubData2D(int con, int id, int xoff, int yoff, int w, int h, int[] d, int sizeBytes);
2452e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAllocationSubData2D(int id, int xoff, int yoff, int w, int h, int[] d, int sizeBytes) {
2462e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAllocationSubData2D(mContext, id, xoff, yoff, w, h, d, sizeBytes);
2472e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2482e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAllocationSubData2D(int con, int id, int xoff, int yoff, int w, int h, float[] d, int sizeBytes);
2492e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAllocationSubData2D(int id, int xoff, int yoff, int w, int h, float[] d, int sizeBytes) {
2502e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAllocationSubData2D(mContext, id, xoff, yoff, w, h, d, sizeBytes);
2512e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2522e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAllocationRead(int con, int id, int[] d);
2532e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAllocationRead(int id, int[] d) {
2542e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAllocationRead(mContext, id, d);
2552e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2562e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAllocationRead(int con, int id, float[] d);
2572e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAllocationRead(int id, float[] d) {
2582e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAllocationRead(mContext, id, d);
2592e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2602e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAllocationSubDataFromObject(int con, int id, Type t, int offset, Object o);
2612e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAllocationSubDataFromObject(int id, Type t, int offset, Object o) {
2622e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAllocationSubDataFromObject(mContext, id, t, offset, o);
2632e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2642e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAllocationSubReadFromObject(int con, int id, Type t, int offset, Object o);
2652e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAllocationSubReadFromObject(int id, Type t, int offset, Object o) {
2662e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAllocationSubReadFromObject(mContext, id, t, offset, o);
2672e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2682e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnAllocationGetType(int con, int id);
2692e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nAllocationGetType(int id) {
2702e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnAllocationGetType(mContext, id);
2712e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2722e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
2732e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnFileA3DCreateFromAssetStream(int con, int assetStream);
2742e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nFileA3DCreateFromAssetStream(int assetStream) {
2752e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnFileA3DCreateFromAssetStream(mContext, assetStream);
2762e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2772e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnFileA3DGetNumIndexEntries(int con, int fileA3D);
2782e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nFileA3DGetNumIndexEntries(int fileA3D) {
2792e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnFileA3DGetNumIndexEntries(mContext, fileA3D);
2802e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2812e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnFileA3DGetIndexEntries(int con, int fileA3D, int numEntries, int[] IDs, String[] names);
2822e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nFileA3DGetIndexEntries(int fileA3D, int numEntries, int[] IDs, String[] names) {
2832e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnFileA3DGetIndexEntries(mContext, fileA3D, numEntries, IDs, names);
2842e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2852e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnFileA3DGetEntryByIndex(int con, int fileA3D, int index);
2862e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nFileA3DGetEntryByIndex(int fileA3D, int index) {
2872e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnFileA3DGetEntryByIndex(mContext, fileA3D, index);
2882e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2892e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
2902e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnFontCreateFromFile(int con, String fileName, int size, int dpi);
2912e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nFontCreateFromFile(String fileName, int size, int dpi) {
2922e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnFontCreateFromFile(mContext, fileName, size, dpi);
2932e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2942e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
2952e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAdapter1DBindAllocation(int con, int ad, int alloc);
2962e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAdapter1DBindAllocation(int ad, int alloc) {
2972e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAdapter1DBindAllocation(mContext, ad, alloc);
2982e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2992e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAdapter1DSetConstraint(int con, int ad, int dim, int value);
3002e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAdapter1DSetConstraint(int ad, int dim, int value) {
3012e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAdapter1DSetConstraint(mContext, ad, dim, value);
3022e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3032e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAdapter1DData(int con, int ad, int[] d);
3042e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAdapter1DData(int ad, int[] d) {
3052e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAdapter1DData(mContext, ad, d);
3062e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3072e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAdapter1DData(int con, int ad, float[] d);
3082e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAdapter1DData(int ad, float[] d) {
3092e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAdapter1DData(mContext, ad, d);
3102e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3112e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAdapter1DSubData(int con, int ad, int off, int count, int[] d);
3122e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAdapter1DSubData(int ad, int off, int count, int[] d) {
3132e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAdapter1DSubData(mContext, ad, off, count, d);
3142e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3152e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAdapter1DSubData(int con, int ad, int off, int count, float[] d);
3162e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAdapter1DSubData(int ad, int off, int count, float[] d) {
3172e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAdapter1DSubData(mContext, ad, off, count, d);
3182e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3192e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnAdapter1DCreate(int con);
3202e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nAdapter1DCreate() {
3212e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnAdapter1DCreate(mContext);
3222e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3232e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
3242e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAdapter2DBindAllocation(int con, int ad, int alloc);
3252e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAdapter2DBindAllocation(int ad, int alloc) {
3262e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAdapter2DBindAllocation(mContext, ad, alloc);
3272e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3282e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAdapter2DSetConstraint(int con, int ad, int dim, int value);
3292e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAdapter2DSetConstraint(int ad, int dim, int value) {
3302e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAdapter2DSetConstraint(mContext, ad, dim, value);
3312e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3322e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAdapter2DData(int con, int ad, int[] d);
3332e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAdapter2DData(int ad, int[] d) {
3342e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAdapter2DData(mContext, ad, d);
3352e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3362e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAdapter2DData(int con, int ad, float[] d);
3372e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAdapter2DData(int ad, float[] d) {
3382e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAdapter2DData(mContext, ad, d);
3392e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3402e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAdapter2DSubData(int con, int ad, int xoff, int yoff, int w, int h, int[] d);
3412e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAdapter2DSubData(int ad, int xoff, int yoff, int w, int h, int[] d) {
3422e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAdapter2DSubData(mContext, ad, xoff, yoff, w, h, d);
3432e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3442e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAdapter2DSubData(int con, int ad, int xoff, int yoff, int w, int h, float[] d);
3452e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAdapter2DSubData(int ad, int xoff, int yoff, int w, int h, float[] d) {
3462e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAdapter2DSubData(mContext, ad, xoff, yoff, w, h, d);
3472e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3482e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnAdapter2DCreate(int con);
3492e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nAdapter2DCreate() {
3502e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnAdapter2DCreate(mContext);
3512e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3522e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
3532e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnScriptBindAllocation(int con, int script, int alloc, int slot);
3542e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nScriptBindAllocation(int script, int alloc, int slot) {
3552e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnScriptBindAllocation(mContext, script, alloc, slot);
3562e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3572e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnScriptSetTimeZone(int con, int script, byte[] timeZone);
3582e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nScriptSetTimeZone(int script, byte[] timeZone) {
3592e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnScriptSetTimeZone(mContext, script, timeZone);
3602e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3612e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnScriptInvoke(int con, int id, int slot);
3622e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nScriptInvoke(int id, int slot) {
3632e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnScriptInvoke(mContext, id, slot);
3642e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3652e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnScriptInvokeV(int con, int id, int slot, byte[] params);
3662e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nScriptInvokeV(int id, int slot, byte[] params) {
3672e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnScriptInvokeV(mContext, id, slot, params);
3682e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3692e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnScriptSetVarI(int con, int id, int slot, int val);
3702e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nScriptSetVarI(int id, int slot, int val) {
3712e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnScriptSetVarI(mContext, id, slot, val);
3722e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3732e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnScriptSetVarF(int con, int id, int slot, float val);
3742e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nScriptSetVarF(int id, int slot, float val) {
3752e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnScriptSetVarF(mContext, id, slot, val);
3762e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3772e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnScriptSetVarV(int con, int id, int slot, byte[] val);
3782e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nScriptSetVarV(int id, int slot, byte[] val) {
3792e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnScriptSetVarV(mContext, id, slot, val);
3802e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3812e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
3822e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnScriptCBegin(int con);
3832e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nScriptCBegin() {
3842e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnScriptCBegin(mContext);
3852e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3862e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnScriptCSetScript(int con, byte[] script, int offset, int length);
3872e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nScriptCSetScript(byte[] script, int offset, int length) {
3882e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnScriptCSetScript(mContext, script, offset, length);
3892e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3902e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnScriptCCreate(int con);
3912e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nScriptCCreate() {
3922e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnScriptCCreate(mContext);
3932e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3942e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
3952e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnSamplerBegin(int con);
3962e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nSamplerBegin() {
3972e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnSamplerBegin(mContext);
3982e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3992e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnSamplerSet(int con, int param, int value);
4002e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nSamplerSet(int param, int value) {
4012e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnSamplerSet(mContext, param, value);
4022e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4032e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnSamplerCreate(int con);
4042e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nSamplerCreate() {
4052e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnSamplerCreate(mContext);
4062e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4072e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
4082e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnProgramStoreBegin(int con, int in, int out);
4092e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nProgramStoreBegin(int in, int out) {
4102e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnProgramStoreBegin(mContext, in, out);
4112e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4122e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnProgramStoreDepthFunc(int con, int func);
4132e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nProgramStoreDepthFunc(int func) {
4142e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnProgramStoreDepthFunc(mContext, func);
4152e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4162e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnProgramStoreDepthMask(int con, boolean enable);
4172e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nProgramStoreDepthMask(boolean enable) {
4182e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnProgramStoreDepthMask(mContext, enable);
4192e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4202e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnProgramStoreColorMask(int con, boolean r, boolean g, boolean b, boolean a);
4212e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nProgramStoreColorMask(boolean r, boolean g, boolean b, boolean a) {
4222e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnProgramStoreColorMask(mContext, r, g, b, a);
4232e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4242e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnProgramStoreBlendFunc(int con, int src, int dst);
4252e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nProgramStoreBlendFunc(int src, int dst) {
4262e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnProgramStoreBlendFunc(mContext, src, dst);
4272e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4282e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnProgramStoreDither(int con, boolean enable);
4292e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nProgramStoreDither(boolean enable) {
4302e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnProgramStoreDither(mContext, enable);
4312e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4322e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnProgramStoreCreate(int con);
4332e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nProgramStoreCreate() {
4342e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnProgramStoreCreate(mContext);
4352e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4362e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
4372e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnProgramRasterCreate(int con, boolean pointSmooth, boolean lineSmooth, boolean pointSprite);
4382e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nProgramRasterCreate(boolean pointSmooth, boolean lineSmooth, boolean pointSprite) {
4392e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnProgramRasterCreate(mContext, pointSmooth, lineSmooth, pointSprite);
4402e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4412e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnProgramRasterSetLineWidth(int con, int pr, float v);
4422e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nProgramRasterSetLineWidth(int pr, float v) {
4432e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnProgramRasterSetLineWidth(mContext, pr, v);
4442e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4452e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnProgramRasterSetCullMode(int con, int pr, int mode);
4462e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nProgramRasterSetCullMode(int pr, int mode) {
4472e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnProgramRasterSetCullMode(mContext, pr, mode);
4482e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4492e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
4502e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnProgramBindConstants(int con, int pv, int slot, int mID);
4512e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nProgramBindConstants(int pv, int slot, int mID) {
4522e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnProgramBindConstants(mContext, pv, slot, mID);
4532e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4542e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnProgramBindTexture(int con, int vpf, int slot, int a);
4552e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nProgramBindTexture(int vpf, int slot, int a) {
4562e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnProgramBindTexture(mContext, vpf, slot, a);
4572e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4582e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnProgramBindSampler(int con, int vpf, int slot, int s);
4592e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nProgramBindSampler(int vpf, int slot, int s) {
4602e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnProgramBindSampler(mContext, vpf, slot, s);
4612e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4622e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
4632e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnProgramFragmentCreate(int con, int[] params);
4642e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nProgramFragmentCreate(int[] params) {
4652e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnProgramFragmentCreate(mContext, params);
4662e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4672e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnProgramFragmentCreate2(int con, String shader, int[] params);
4682e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nProgramFragmentCreate2(String shader, int[] params) {
4692e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnProgramFragmentCreate2(mContext, shader, params);
4702e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4712e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
4722e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnProgramVertexCreate(int con, boolean texMat);
4732e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nProgramVertexCreate(boolean texMat) {
4742e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnProgramVertexCreate(mContext, texMat);
4752e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4762e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnProgramVertexCreate2(int con, String shader, int[] params);
4772e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nProgramVertexCreate2(String shader, int[] params) {
4782e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnProgramVertexCreate2(mContext, shader, params);
4792e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4802e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
4812e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
4822e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnMeshCreate(int con, int vtxCount, int indexCount);
4832e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nMeshCreate(int vtxCount, int indexCount) {
4842e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnMeshCreate(mContext, vtxCount, indexCount);
4852e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4862e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnMeshBindVertex(int con, int id, int alloc, int slot);
4872e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nMeshBindVertex(int id, int alloc, int slot) {
4882e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnMeshBindVertex(mContext, id, alloc, slot);
4892e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4902e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnMeshBindIndex(int con, int id, int alloc, int prim, int slot);
4912e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nMeshBindIndex(int id, int alloc, int prim, int slot) {
4922e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnMeshBindIndex(mContext, id, alloc, prim, slot);
4932e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4942e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnMeshGetVertexBufferCount(int con, int id);
4952e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nMeshGetVertexBufferCount(int id) {
4962e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnMeshGetVertexBufferCount(mContext, id);
4972e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4982e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnMeshGetIndexCount(int con, int id);
4992e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nMeshGetIndexCount(int id) {
5002e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnMeshGetIndexCount(mContext, id);
5012e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
5022e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnMeshGetVertices(int con, int id, int[] vtxIds, int vtxIdCount);
5032e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nMeshGetVertices(int id, int[] vtxIds, int vtxIdCount) {
5042e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnMeshGetVertices(mContext, id, vtxIds, vtxIdCount);
5052e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
5062e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnMeshGetIndices(int con, int id, int[] idxIds, int[] primitives, int vtxIdCount);
5072e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nMeshGetIndices(int id, int[] idxIds, int[] primitives, int vtxIdCount) {
5082e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnMeshGetIndices(mContext, id, idxIds, primitives, vtxIdCount);
5092e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
5102e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
51160aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
512704ff64b099406bb328898a7443921f22dbffd6dJason Sams    protected int     mDev;
513704ff64b099406bb328898a7443921f22dbffd6dJason Sams    protected int     mContext;
514650a3eb7d621dc8e81573142a4498bbd07bcde27Romain Guy    @SuppressWarnings({"FieldCanBeLocal"})
515704ff64b099406bb328898a7443921f22dbffd6dJason Sams    protected MessageThread mMessageThread;
51660aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
5178cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_U8;
5188cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_I8;
5198cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_U16;
5208cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_I16;
5218cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_U32;
5228cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_I32;
5238cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_F32;
524f110d4b787b91dabe968a812e76e5c1f8d953487Jason Sams    Element mElement_BOOLEAN;
5258cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams
5268cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_ELEMENT;
5278cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_TYPE;
5288cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_ALLOCATION;
5298cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_SAMPLER;
5308cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_SCRIPT;
5318cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_MESH;
5328cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_PROGRAM_FRAGMENT;
5338cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_PROGRAM_VERTEX;
5348cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_PROGRAM_RASTER;
5358cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_PROGRAM_STORE;
536a70f416c9cf2fc6cc5e132c1d656ce07441d6b82Jason Sams
5373c0dfbab807a459622aeade4940daddf482dec66Jason Sams    Element mElement_A_8;
5383c0dfbab807a459622aeade4940daddf482dec66Jason Sams    Element mElement_RGB_565;
5393c0dfbab807a459622aeade4940daddf482dec66Jason Sams    Element mElement_RGB_888;
5403c0dfbab807a459622aeade4940daddf482dec66Jason Sams    Element mElement_RGBA_5551;
5413c0dfbab807a459622aeade4940daddf482dec66Jason Sams    Element mElement_RGBA_4444;
5423c0dfbab807a459622aeade4940daddf482dec66Jason Sams    Element mElement_RGBA_8888;
5433c0dfbab807a459622aeade4940daddf482dec66Jason Sams
5448cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_FLOAT_2;
5458cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_FLOAT_3;
5468cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_FLOAT_4;
5478cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_UCHAR_4;
5487d787b4722eaeb79cab42c36060336e092b77b5fJason Sams
5494d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    Sampler mSampler_CLAMP_NEAREST;
5504d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    Sampler mSampler_CLAMP_LINEAR;
5514d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    Sampler mSampler_CLAMP_LINEAR_MIP_LINEAR;
5524d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    Sampler mSampler_WRAP_NEAREST;
5534d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    Sampler mSampler_WRAP_LINEAR;
5544d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    Sampler mSampler_WRAP_LINEAR_MIP_LINEAR;
5554d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams
55660aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich    ///////////////////////////////////////////////////////////////////////////////////
55743702d8925c54360ad5f9f66b0d35d61d59f6910Jack Palevich    //
55860aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
559516c31911578db8ce53529483c3ded918ac7dc6bJason Sams    public static class RSMessage implements Runnable {
560516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        protected int[] mData;
561516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        protected int mID;
562516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        public void run() {
563516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        }
564516c31911578db8ce53529483c3ded918ac7dc6bJason Sams    }
565516c31911578db8ce53529483c3ded918ac7dc6bJason Sams    public RSMessage mMessageCallback = null;
566516c31911578db8ce53529483c3ded918ac7dc6bJason Sams
5677d787b4722eaeb79cab42c36060336e092b77b5fJason Sams    public enum Priority {
5687d787b4722eaeb79cab42c36060336e092b77b5fJason Sams        LOW (5),     //ANDROID_PRIORITY_BACKGROUND + 5
5697d787b4722eaeb79cab42c36060336e092b77b5fJason Sams        NORMAL (-4);  //ANDROID_PRIORITY_DISPLAY
5707d787b4722eaeb79cab42c36060336e092b77b5fJason Sams
5717d787b4722eaeb79cab42c36060336e092b77b5fJason Sams        int mID;
5727d787b4722eaeb79cab42c36060336e092b77b5fJason Sams        Priority(int id) {
5737d787b4722eaeb79cab42c36060336e092b77b5fJason Sams            mID = id;
5747d787b4722eaeb79cab42c36060336e092b77b5fJason Sams        }
5757d787b4722eaeb79cab42c36060336e092b77b5fJason Sams    }
5767d787b4722eaeb79cab42c36060336e092b77b5fJason Sams
577771bebb94054d06f97284379c93a2620613513c3Jason Sams    void validate() {
578771bebb94054d06f97284379c93a2620613513c3Jason Sams        if (mContext == 0) {
579771bebb94054d06f97284379c93a2620613513c3Jason Sams            throw new IllegalStateException("Calling RS with no Context active.");
580771bebb94054d06f97284379c93a2620613513c3Jason Sams        }
581771bebb94054d06f97284379c93a2620613513c3Jason Sams    }
582771bebb94054d06f97284379c93a2620613513c3Jason Sams
5837d787b4722eaeb79cab42c36060336e092b77b5fJason Sams    public void contextSetPriority(Priority p) {
5845dbfe93b3f15f3a837836d024958635fd8f9ad14Jason Sams        validate();
5857d787b4722eaeb79cab42c36060336e092b77b5fJason Sams        nContextSetPriority(p.mID);
5867d787b4722eaeb79cab42c36060336e092b77b5fJason Sams    }
5877d787b4722eaeb79cab42c36060336e092b77b5fJason Sams
588704ff64b099406bb328898a7443921f22dbffd6dJason Sams    protected static class MessageThread extends Thread {
589516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        RenderScript mRS;
590516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        boolean mRun = true;
591516c31911578db8ce53529483c3ded918ac7dc6bJason Sams
592516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        MessageThread(RenderScript rs) {
593516c31911578db8ce53529483c3ded918ac7dc6bJason Sams            super("RSMessageThread");
594516c31911578db8ce53529483c3ded918ac7dc6bJason Sams            mRS = rs;
595516c31911578db8ce53529483c3ded918ac7dc6bJason Sams
596516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        }
597516c31911578db8ce53529483c3ded918ac7dc6bJason Sams
598516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        public void run() {
599516c31911578db8ce53529483c3ded918ac7dc6bJason Sams            // This function is a temporary solution.  The final solution will
600516c31911578db8ce53529483c3ded918ac7dc6bJason Sams            // used typed allocations where the message id is the type indicator.
601516c31911578db8ce53529483c3ded918ac7dc6bJason Sams            int[] rbuf = new int[16];
6022e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams            mRS.nContextInitToClient(mRS.mContext);
603516c31911578db8ce53529483c3ded918ac7dc6bJason Sams            while(mRun) {
6042e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams                int msg = mRS.nContextGetMessage(mRS.mContext, rbuf, true);
605516c31911578db8ce53529483c3ded918ac7dc6bJason Sams                if (msg == 0) {
606516c31911578db8ce53529483c3ded918ac7dc6bJason Sams                    // Should only happen during teardown.
607516c31911578db8ce53529483c3ded918ac7dc6bJason Sams                    // But we want to avoid starving other threads during
608516c31911578db8ce53529483c3ded918ac7dc6bJason Sams                    // teardown by yielding until the next line in the destructor
609516c31911578db8ce53529483c3ded918ac7dc6bJason Sams                    // can execute to set mRun = false
610516c31911578db8ce53529483c3ded918ac7dc6bJason Sams                    try {
611516c31911578db8ce53529483c3ded918ac7dc6bJason Sams                        sleep(1, 0);
612516c31911578db8ce53529483c3ded918ac7dc6bJason Sams                    } catch(InterruptedException e) {
613516c31911578db8ce53529483c3ded918ac7dc6bJason Sams                    }
614516c31911578db8ce53529483c3ded918ac7dc6bJason Sams                }
615516c31911578db8ce53529483c3ded918ac7dc6bJason Sams                if(mRS.mMessageCallback != null) {
616516c31911578db8ce53529483c3ded918ac7dc6bJason Sams                    mRS.mMessageCallback.mData = rbuf;
617516c31911578db8ce53529483c3ded918ac7dc6bJason Sams                    mRS.mMessageCallback.mID = msg;
618516c31911578db8ce53529483c3ded918ac7dc6bJason Sams                    mRS.mMessageCallback.run();
619516c31911578db8ce53529483c3ded918ac7dc6bJason Sams                }
620516c31911578db8ce53529483c3ded918ac7dc6bJason Sams            }
6213bc47d438171dce294e816366d53bc9eca772c5bJason Sams            Log.d(LOG_TAG, "MessageThread exiting.");
622516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        }
623516c31911578db8ce53529483c3ded918ac7dc6bJason Sams    }
624516c31911578db8ce53529483c3ded918ac7dc6bJason Sams
625704ff64b099406bb328898a7443921f22dbffd6dJason Sams    protected RenderScript() {
62660aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich    }
62760aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
628704ff64b099406bb328898a7443921f22dbffd6dJason Sams    public static RenderScript create() {
629704ff64b099406bb328898a7443921f22dbffd6dJason Sams        RenderScript rs = new RenderScript();
630704ff64b099406bb328898a7443921f22dbffd6dJason Sams
631704ff64b099406bb328898a7443921f22dbffd6dJason Sams        rs.mDev = rs.nDeviceCreate();
632704ff64b099406bb328898a7443921f22dbffd6dJason Sams        rs.mContext = rs.nContextCreate(rs.mDev, 0);
633704ff64b099406bb328898a7443921f22dbffd6dJason Sams        rs.mMessageThread = new MessageThread(rs);
634704ff64b099406bb328898a7443921f22dbffd6dJason Sams        rs.mMessageThread.start();
635704ff64b099406bb328898a7443921f22dbffd6dJason Sams        Element.initPredefined(rs);
636704ff64b099406bb328898a7443921f22dbffd6dJason Sams        return rs;
637efd9b6fb2e0f31b50db089352118e5daeb268879Jason Sams    }
638efd9b6fb2e0f31b50db089352118e5daeb268879Jason Sams
639715333b832fb448c32165c7d97d408a3fa43f7cbJason Sams    public void contextDump(int bits) {
6405dbfe93b3f15f3a837836d024958635fd8f9ad14Jason Sams        validate();
641715333b832fb448c32165c7d97d408a3fa43f7cbJason Sams        nContextDump(bits);
642715333b832fb448c32165c7d97d408a3fa43f7cbJason Sams    }
643715333b832fb448c32165c7d97d408a3fa43f7cbJason Sams
64496ed4cfa62dd09aafb3f9da01e047661b4fe3c95Jason Sams    public void finish() {
64596ed4cfa62dd09aafb3f9da01e047661b4fe3c95Jason Sams        nContextFinish();
64696ed4cfa62dd09aafb3f9da01e047661b4fe3c95Jason Sams    }
64796ed4cfa62dd09aafb3f9da01e047661b4fe3c95Jason Sams
648f5b4596a383b6ab83f92edecfe054e80b555c2d0Jason Sams    public void destroy() {
6495dbfe93b3f15f3a837836d024958635fd8f9ad14Jason Sams        validate();
6502e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        nContextDeinitToClient(mContext);
651516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        mMessageThread.mRun = false;
652516c31911578db8ce53529483c3ded918ac7dc6bJason Sams
6532e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        nContextDestroy();
654f5b4596a383b6ab83f92edecfe054e80b555c2d0Jason Sams        mContext = 0;
655f5b4596a383b6ab83f92edecfe054e80b555c2d0Jason Sams
656f5b4596a383b6ab83f92edecfe054e80b555c2d0Jason Sams        nDeviceDestroy(mDev);
657f5b4596a383b6ab83f92edecfe054e80b555c2d0Jason Sams        mDev = 0;
658f5b4596a383b6ab83f92edecfe054e80b555c2d0Jason Sams    }
65902fb2cb531035779a25dbf9595e0628ea40585b0Jason Sams
660a9e7a05b84470257637c97d65f6562aa832c66efJason Sams    boolean isAlive() {
661a9e7a05b84470257637c97d65f6562aa832c66efJason Sams        return mContext != 0;
662a9e7a05b84470257637c97d65f6562aa832c66efJason Sams    }
663a9e7a05b84470257637c97d65f6562aa832c66efJason Sams
66460aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich    ///////////////////////////////////////////////////////////////////////////////////
66560aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich    // Root state
66660aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
667704ff64b099406bb328898a7443921f22dbffd6dJason Sams    protected int safeID(BaseObj o) {
6686b9dec00afec359f091ed353f371f08ff150278aJason Sams        if(o != null) {
6696b9dec00afec359f091ed353f371f08ff150278aJason Sams            return o.mID;
670d8e4161f114331343b897cbacea927e7e60e7b17Jason Sams        }
6716b9dec00afec359f091ed353f371f08ff150278aJason Sams        return 0;
67260aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich    }
67360aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich}
67460aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
67536e612a488511940b61f09803b270aa1c61b68e0Jason Sams
67680a4c2cd34aedb4f1a2e5e7d1ac26a9aeebe41aeAlex Sakhartchouk
677