RenderScript.java revision ef1dac28d3bf98bd61cd9874fb3ccab42105e9b6
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 int  rsnFileOpen(int con, byte[] name);
1472e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nFileOpen(byte[] name) {
1482e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnFileOpen(mContext, name);
1492e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1502e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
1512e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnElementCreate(int con, int type, int kind, boolean norm, int vecSize);
1522e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nElementCreate(int type, int kind, boolean norm, int vecSize) {
1532e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnElementCreate(mContext, type, kind, norm, vecSize);
1542e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
15570d4e5024298f71edb3b04867e05568f5495b4ceJason Sams    native int  rsnElementCreate2(int con, int[] elements, String[] names, int[] arraySizes);
15670d4e5024298f71edb3b04867e05568f5495b4ceJason Sams    synchronized int nElementCreate2(int[] elements, String[] names, int[] arraySizes) {
15770d4e5024298f71edb3b04867e05568f5495b4ceJason Sams        return rsnElementCreate2(mContext, elements, names, arraySizes);
1582e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1592e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnElementGetNativeData(int con, int id, int[] elementData);
1602e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nElementGetNativeData(int id, int[] elementData) {
1612e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnElementGetNativeData(mContext, id, elementData);
1622e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1632e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnElementGetSubElements(int con, int id, int[] IDs, String[] names);
1642e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nElementGetSubElements(int id, int[] IDs, String[] names) {
1652e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnElementGetSubElements(mContext, id, IDs, names);
1662e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1672e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
1682e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnTypeBegin(int con, int elementID);
1692e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nTypeBegin(int elementID) {
1702e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnTypeBegin(mContext, elementID);
1712e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1722e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnTypeAdd(int con, int dim, int val);
1732e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nTypeAdd(int dim, int val) {
1742e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnTypeAdd(mContext, dim, val);
1752e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1762e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnTypeCreate(int con);
1772e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nTypeCreate() {
1782e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnTypeCreate(mContext);
1792e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1802e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnTypeGetNativeData(int con, int id, int[] typeData);
1812e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nTypeGetNativeData(int id, int[] typeData) {
1822e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnTypeGetNativeData(mContext, id, typeData);
1832e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1842e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
1852e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnAllocationCreateTyped(int con, int type);
1862e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nAllocationCreateTyped(int type) {
1872e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnAllocationCreateTyped(mContext, type);
1882e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1892e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnAllocationCreateFromBitmap(int con, int dstFmt, boolean genMips, Bitmap bmp);
1902e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nAllocationCreateFromBitmap(int dstFmt, boolean genMips, Bitmap bmp) {
1912e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnAllocationCreateFromBitmap(mContext, dstFmt, genMips, bmp);
1922e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1932e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnAllocationCreateBitmapRef(int con, int type, Bitmap bmp);
1942e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nAllocationCreateBitmapRef(int type, Bitmap bmp) {
1952e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnAllocationCreateBitmapRef(mContext, type, bmp);
1962e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
1972e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnAllocationCreateFromBitmapBoxed(int con, int dstFmt, boolean genMips, Bitmap bmp);
1982e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nAllocationCreateFromBitmapBoxed(int dstFmt, boolean genMips, Bitmap bmp) {
1992e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnAllocationCreateFromBitmapBoxed(mContext, dstFmt, genMips, bmp);
2002e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2012e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnAllocationCreateFromAssetStream(int con, int dstFmt, boolean genMips, int assetStream);
2022e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nAllocationCreateFromAssetStream(int dstFmt, boolean genMips, int assetStream) {
2032e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnAllocationCreateFromAssetStream(mContext, dstFmt, genMips, assetStream);
2042e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2052e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
2062e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAllocationUploadToTexture(int con, int alloc, boolean genMips, int baseMioLevel);
2072e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAllocationUploadToTexture(int alloc, boolean genMips, int baseMioLevel) {
2082e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAllocationUploadToTexture(mContext, alloc, genMips, baseMioLevel);
2092e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2102e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAllocationUploadToBufferObject(int con, int alloc);
2112e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAllocationUploadToBufferObject(int alloc) {
2122e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAllocationUploadToBufferObject(mContext, alloc);
2132e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2142e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
2152e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAllocationSubData1D(int con, int id, int off, int count, int[] d, int sizeBytes);
2162e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAllocationSubData1D(int id, int off, int count, int[] d, int sizeBytes) {
2172e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAllocationSubData1D(mContext, id, off, count, d, sizeBytes);
2182e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2192e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAllocationSubData1D(int con, int id, int off, int count, short[] d, int sizeBytes);
2202e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAllocationSubData1D(int id, int off, int count, short[] d, int sizeBytes) {
2212e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAllocationSubData1D(mContext, id, off, count, d, sizeBytes);
2222e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2232e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAllocationSubData1D(int con, int id, int off, int count, byte[] d, int sizeBytes);
2242e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAllocationSubData1D(int id, int off, int count, byte[] d, int sizeBytes) {
2252e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAllocationSubData1D(mContext, id, off, count, d, sizeBytes);
2262e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
22749bdaf0293408159df18a1d8540360f9623c40f7Jason Sams    native void rsnAllocationSubElementData1D(int con, int id, int xoff, int compIdx, byte[] d, int sizeBytes);
22849bdaf0293408159df18a1d8540360f9623c40f7Jason Sams    synchronized void nAllocationSubElementData1D(int id, int xoff, int compIdx, byte[] d, int sizeBytes) {
22949bdaf0293408159df18a1d8540360f9623c40f7Jason Sams        rsnAllocationSubElementData1D(mContext, id, xoff, compIdx, d, sizeBytes);
23049bdaf0293408159df18a1d8540360f9623c40f7Jason Sams    }
2312e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAllocationSubData1D(int con, int id, int off, int count, float[] d, int sizeBytes);
2322e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAllocationSubData1D(int id, int off, int count, float[] d, int sizeBytes) {
2332e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAllocationSubData1D(mContext, id, off, count, d, sizeBytes);
2342e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2352e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
2362e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAllocationSubData2D(int con, int id, int xoff, int yoff, int w, int h, int[] d, int sizeBytes);
2372e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAllocationSubData2D(int id, int xoff, int yoff, int w, int h, int[] d, int sizeBytes) {
2382e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAllocationSubData2D(mContext, id, xoff, yoff, w, h, d, sizeBytes);
2392e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2402e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAllocationSubData2D(int con, int id, int xoff, int yoff, int w, int h, float[] d, int sizeBytes);
2412e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAllocationSubData2D(int id, int xoff, int yoff, int w, int h, float[] d, int sizeBytes) {
2422e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAllocationSubData2D(mContext, id, xoff, yoff, w, h, d, sizeBytes);
2432e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2442e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAllocationRead(int con, int id, int[] d);
2452e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAllocationRead(int id, int[] d) {
2462e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAllocationRead(mContext, id, d);
2472e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2482e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAllocationRead(int con, int id, float[] d);
2492e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAllocationRead(int id, float[] d) {
2502e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAllocationRead(mContext, id, d);
2512e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2522e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnAllocationGetType(int con, int id);
2532e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nAllocationGetType(int id) {
2542e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnAllocationGetType(mContext, id);
2552e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2562e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
2572e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnFileA3DCreateFromAssetStream(int con, int assetStream);
2582e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nFileA3DCreateFromAssetStream(int assetStream) {
2592e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnFileA3DCreateFromAssetStream(mContext, assetStream);
2602e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2612e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnFileA3DGetNumIndexEntries(int con, int fileA3D);
2622e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nFileA3DGetNumIndexEntries(int fileA3D) {
2632e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnFileA3DGetNumIndexEntries(mContext, fileA3D);
2642e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2652e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnFileA3DGetIndexEntries(int con, int fileA3D, int numEntries, int[] IDs, String[] names);
2662e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nFileA3DGetIndexEntries(int fileA3D, int numEntries, int[] IDs, String[] names) {
2672e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnFileA3DGetIndexEntries(mContext, fileA3D, numEntries, IDs, names);
2682e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2692e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnFileA3DGetEntryByIndex(int con, int fileA3D, int index);
2702e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nFileA3DGetEntryByIndex(int fileA3D, int index) {
2712e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnFileA3DGetEntryByIndex(mContext, fileA3D, index);
2722e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2732e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
2742e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnFontCreateFromFile(int con, String fileName, int size, int dpi);
2752e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nFontCreateFromFile(String fileName, int size, int dpi) {
2762e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnFontCreateFromFile(mContext, fileName, size, dpi);
2772e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2782e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
2792e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAdapter1DBindAllocation(int con, int ad, int alloc);
2802e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAdapter1DBindAllocation(int ad, int alloc) {
2812e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAdapter1DBindAllocation(mContext, ad, alloc);
2822e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2832e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAdapter1DSetConstraint(int con, int ad, int dim, int value);
2842e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAdapter1DSetConstraint(int ad, int dim, int value) {
2852e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAdapter1DSetConstraint(mContext, ad, dim, value);
2862e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2872e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAdapter1DData(int con, int ad, int[] d);
2882e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAdapter1DData(int ad, int[] d) {
2892e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAdapter1DData(mContext, ad, d);
2902e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2912e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAdapter1DData(int con, int ad, float[] d);
2922e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAdapter1DData(int ad, float[] d) {
2932e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAdapter1DData(mContext, ad, d);
2942e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2952e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAdapter1DSubData(int con, int ad, int off, int count, int[] d);
2962e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAdapter1DSubData(int ad, int off, int count, int[] d) {
2972e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAdapter1DSubData(mContext, ad, off, count, d);
2982e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
2992e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAdapter1DSubData(int con, int ad, int off, int count, float[] d);
3002e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAdapter1DSubData(int ad, int off, int count, float[] d) {
3012e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAdapter1DSubData(mContext, ad, off, count, d);
3022e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3032e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnAdapter1DCreate(int con);
3042e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nAdapter1DCreate() {
3052e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnAdapter1DCreate(mContext);
3062e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3072e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
3082e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAdapter2DBindAllocation(int con, int ad, int alloc);
3092e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAdapter2DBindAllocation(int ad, int alloc) {
3102e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAdapter2DBindAllocation(mContext, ad, alloc);
3112e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3122e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAdapter2DSetConstraint(int con, int ad, int dim, int value);
3132e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAdapter2DSetConstraint(int ad, int dim, int value) {
3142e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAdapter2DSetConstraint(mContext, ad, dim, value);
3152e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3162e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAdapter2DData(int con, int ad, int[] d);
3172e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAdapter2DData(int ad, int[] d) {
3182e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAdapter2DData(mContext, ad, d);
3192e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3202e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAdapter2DData(int con, int ad, float[] d);
3212e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAdapter2DData(int ad, float[] d) {
3222e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAdapter2DData(mContext, ad, d);
3232e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3242e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAdapter2DSubData(int con, int ad, int xoff, int yoff, int w, int h, int[] d);
3252e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAdapter2DSubData(int ad, int xoff, int yoff, int w, int h, int[] d) {
3262e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAdapter2DSubData(mContext, ad, xoff, yoff, w, h, d);
3272e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3282e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnAdapter2DSubData(int con, int ad, int xoff, int yoff, int w, int h, float[] d);
3292e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nAdapter2DSubData(int ad, int xoff, int yoff, int w, int h, float[] d) {
3302e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnAdapter2DSubData(mContext, ad, xoff, yoff, w, h, d);
3312e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3322e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnAdapter2DCreate(int con);
3332e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nAdapter2DCreate() {
3342e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnAdapter2DCreate(mContext);
3352e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3362e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
3372e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnScriptBindAllocation(int con, int script, int alloc, int slot);
3382e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nScriptBindAllocation(int script, int alloc, int slot) {
3392e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnScriptBindAllocation(mContext, script, alloc, slot);
3402e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3412e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnScriptSetTimeZone(int con, int script, byte[] timeZone);
3422e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nScriptSetTimeZone(int script, byte[] timeZone) {
3432e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnScriptSetTimeZone(mContext, script, timeZone);
3442e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3452e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnScriptInvoke(int con, int id, int slot);
3462e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nScriptInvoke(int id, int slot) {
3472e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnScriptInvoke(mContext, id, slot);
3482e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3492e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnScriptInvokeV(int con, int id, int slot, byte[] params);
3502e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nScriptInvokeV(int id, int slot, byte[] params) {
3512e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnScriptInvokeV(mContext, id, slot, params);
3522e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3532e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnScriptSetVarI(int con, int id, int slot, int val);
3542e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nScriptSetVarI(int id, int slot, int val) {
3552e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnScriptSetVarI(mContext, id, slot, val);
3562e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3572e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnScriptSetVarF(int con, int id, int slot, float val);
3582e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nScriptSetVarF(int id, int slot, float val) {
3592e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnScriptSetVarF(mContext, id, slot, val);
3602e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
361ca54ec302f5bddd1674ea1f36cd3b7c540b2fbcaStephen Hines    native void rsnScriptSetVarD(int con, int id, int slot, double val);
362ca54ec302f5bddd1674ea1f36cd3b7c540b2fbcaStephen Hines    synchronized void nScriptSetVarD(int id, int slot, double val) {
363ca54ec302f5bddd1674ea1f36cd3b7c540b2fbcaStephen Hines        rsnScriptSetVarD(mContext, id, slot, val);
364ca54ec302f5bddd1674ea1f36cd3b7c540b2fbcaStephen Hines    }
3652e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnScriptSetVarV(int con, int id, int slot, byte[] val);
3662e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nScriptSetVarV(int id, int slot, byte[] val) {
3672e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnScriptSetVarV(mContext, id, slot, val);
3682e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3692e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
3702e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnScriptCBegin(int con);
3712e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nScriptCBegin() {
3722e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnScriptCBegin(mContext);
3732e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3742e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnScriptCSetScript(int con, byte[] script, int offset, int length);
3752e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nScriptCSetScript(byte[] script, int offset, int length) {
3762e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnScriptCSetScript(mContext, script, offset, length);
3772e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3782e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnScriptCCreate(int con);
3792e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nScriptCCreate() {
3802e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnScriptCCreate(mContext);
3812e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3822e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
3832e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnSamplerBegin(int con);
3842e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nSamplerBegin() {
3852e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnSamplerBegin(mContext);
3862e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3872e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnSamplerSet(int con, int param, int value);
3882e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nSamplerSet(int param, int value) {
3892e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnSamplerSet(mContext, param, value);
3902e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
391f5b3510c706ed1f7611760dff0c94f2111531c68Alex Sakhartchouk    native void rsnSamplerSet2(int con, int param, float value);
392f5b3510c706ed1f7611760dff0c94f2111531c68Alex Sakhartchouk    synchronized void nSamplerSet2(int param, float value) {
393f5b3510c706ed1f7611760dff0c94f2111531c68Alex Sakhartchouk        rsnSamplerSet2(mContext, param, value);
394f5b3510c706ed1f7611760dff0c94f2111531c68Alex Sakhartchouk    }
3952e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnSamplerCreate(int con);
3962e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nSamplerCreate() {
3972e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnSamplerCreate(mContext);
3982e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
3992e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
4002e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnProgramStoreBegin(int con, int in, int out);
4012e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nProgramStoreBegin(int in, int out) {
4022e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnProgramStoreBegin(mContext, in, out);
4032e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4042e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnProgramStoreDepthFunc(int con, int func);
4052e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nProgramStoreDepthFunc(int func) {
4062e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnProgramStoreDepthFunc(mContext, func);
4072e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4082e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnProgramStoreDepthMask(int con, boolean enable);
4092e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nProgramStoreDepthMask(boolean enable) {
4102e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnProgramStoreDepthMask(mContext, enable);
4112e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4122e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnProgramStoreColorMask(int con, boolean r, boolean g, boolean b, boolean a);
4132e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nProgramStoreColorMask(boolean r, boolean g, boolean b, boolean a) {
4142e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnProgramStoreColorMask(mContext, r, g, b, a);
4152e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4162e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnProgramStoreBlendFunc(int con, int src, int dst);
4172e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nProgramStoreBlendFunc(int src, int dst) {
4182e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnProgramStoreBlendFunc(mContext, src, dst);
4192e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4202e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnProgramStoreDither(int con, boolean enable);
4212e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nProgramStoreDither(boolean enable) {
4222e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnProgramStoreDither(mContext, enable);
4232e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4242e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnProgramStoreCreate(int con);
4252e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nProgramStoreCreate() {
4262e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnProgramStoreCreate(mContext);
4272e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4282e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
4292e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnProgramRasterCreate(int con, boolean pointSmooth, boolean lineSmooth, boolean pointSprite);
4302e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nProgramRasterCreate(boolean pointSmooth, boolean lineSmooth, boolean pointSprite) {
4312e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnProgramRasterCreate(mContext, pointSmooth, lineSmooth, pointSprite);
4322e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4332e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnProgramRasterSetLineWidth(int con, int pr, float v);
4342e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nProgramRasterSetLineWidth(int pr, float v) {
4352e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnProgramRasterSetLineWidth(mContext, pr, v);
4362e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4372e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnProgramRasterSetCullMode(int con, int pr, int mode);
4382e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nProgramRasterSetCullMode(int pr, int mode) {
4392e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnProgramRasterSetCullMode(mContext, pr, mode);
4402e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4412e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
4422e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnProgramBindConstants(int con, int pv, int slot, int mID);
4432e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nProgramBindConstants(int pv, int slot, int mID) {
4442e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnProgramBindConstants(mContext, pv, slot, mID);
4452e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4462e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnProgramBindTexture(int con, int vpf, int slot, int a);
4472e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nProgramBindTexture(int vpf, int slot, int a) {
4482e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnProgramBindTexture(mContext, vpf, slot, a);
4492e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4502e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnProgramBindSampler(int con, int vpf, int slot, int s);
4512e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nProgramBindSampler(int vpf, int slot, int s) {
4522e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnProgramBindSampler(mContext, vpf, slot, s);
4532e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
454b89aaacb2ca9d062e0a17a32e3d4dbf3f6948a17Alex Sakhartchouk    native int  rsnProgramFragmentCreate(int con, String shader, int[] params);
455b89aaacb2ca9d062e0a17a32e3d4dbf3f6948a17Alex Sakhartchouk    synchronized int nProgramFragmentCreate(String shader, int[] params) {
456b89aaacb2ca9d062e0a17a32e3d4dbf3f6948a17Alex Sakhartchouk        return rsnProgramFragmentCreate(mContext, shader, params);
4572e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
458b89aaacb2ca9d062e0a17a32e3d4dbf3f6948a17Alex Sakhartchouk    native int  rsnProgramVertexCreate(int con, String shader, int[] params);
459b89aaacb2ca9d062e0a17a32e3d4dbf3f6948a17Alex Sakhartchouk    synchronized int nProgramVertexCreate(String shader, int[] params) {
460b89aaacb2ca9d062e0a17a32e3d4dbf3f6948a17Alex Sakhartchouk        return rsnProgramVertexCreate(mContext, shader, params);
4612e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4622e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
4632e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnMeshCreate(int con, int vtxCount, int indexCount);
4642e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nMeshCreate(int vtxCount, int indexCount) {
4652e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnMeshCreate(mContext, vtxCount, indexCount);
4662e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4672e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnMeshBindVertex(int con, int id, int alloc, int slot);
4682e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nMeshBindVertex(int id, int alloc, int slot) {
4692e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnMeshBindVertex(mContext, id, alloc, slot);
4702e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4712e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnMeshBindIndex(int con, int id, int alloc, int prim, int slot);
4722e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nMeshBindIndex(int id, int alloc, int prim, int slot) {
4732e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnMeshBindIndex(mContext, id, alloc, prim, slot);
4742e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4752e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnMeshGetVertexBufferCount(int con, int id);
4762e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nMeshGetVertexBufferCount(int id) {
4772e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnMeshGetVertexBufferCount(mContext, id);
4782e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4792e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native int  rsnMeshGetIndexCount(int con, int id);
4802e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized int nMeshGetIndexCount(int id) {
4812e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        return rsnMeshGetIndexCount(mContext, id);
4822e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4832e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnMeshGetVertices(int con, int id, int[] vtxIds, int vtxIdCount);
4842e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nMeshGetVertices(int id, int[] vtxIds, int vtxIdCount) {
4852e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnMeshGetVertices(mContext, id, vtxIds, vtxIdCount);
4862e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4872e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    native void rsnMeshGetIndices(int con, int id, int[] idxIds, int[] primitives, int vtxIdCount);
4882e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    synchronized void nMeshGetIndices(int id, int[] idxIds, int[] primitives, int vtxIdCount) {
4892e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        rsnMeshGetIndices(mContext, id, idxIds, primitives, vtxIdCount);
4902e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams    }
4912e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams
49260aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
493704ff64b099406bb328898a7443921f22dbffd6dJason Sams    protected int     mDev;
494704ff64b099406bb328898a7443921f22dbffd6dJason Sams    protected int     mContext;
495650a3eb7d621dc8e81573142a4498bbd07bcde27Romain Guy    @SuppressWarnings({"FieldCanBeLocal"})
496704ff64b099406bb328898a7443921f22dbffd6dJason Sams    protected MessageThread mMessageThread;
49760aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
4988cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_U8;
4998cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_I8;
5008cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_U16;
5018cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_I16;
5028cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_U32;
5038cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_I32;
504ef1dac28d3bf98bd61cd9874fb3ccab42105e9b6Stephen Hines    Element mElement_I64;
5058cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_F32;
50602f41705199336f808ece50d81585450e7f8f61fStephen Hines    Element mElement_F64;
507f110d4b787b91dabe968a812e76e5c1f8d953487Jason Sams    Element mElement_BOOLEAN;
5088cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams
5098cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_ELEMENT;
5108cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_TYPE;
5118cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_ALLOCATION;
5128cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_SAMPLER;
5138cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_SCRIPT;
5148cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_MESH;
5158cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_PROGRAM_FRAGMENT;
5168cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_PROGRAM_VERTEX;
5178cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_PROGRAM_RASTER;
5188cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_PROGRAM_STORE;
519a70f416c9cf2fc6cc5e132c1d656ce07441d6b82Jason Sams
5203c0dfbab807a459622aeade4940daddf482dec66Jason Sams    Element mElement_A_8;
5213c0dfbab807a459622aeade4940daddf482dec66Jason Sams    Element mElement_RGB_565;
5223c0dfbab807a459622aeade4940daddf482dec66Jason Sams    Element mElement_RGB_888;
5233c0dfbab807a459622aeade4940daddf482dec66Jason Sams    Element mElement_RGBA_5551;
5243c0dfbab807a459622aeade4940daddf482dec66Jason Sams    Element mElement_RGBA_4444;
5253c0dfbab807a459622aeade4940daddf482dec66Jason Sams    Element mElement_RGBA_8888;
5263c0dfbab807a459622aeade4940daddf482dec66Jason Sams
5278cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_FLOAT_2;
5288cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_FLOAT_3;
5298cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_FLOAT_4;
5308cb39de03aef6097a90033600d11a60ae000a6e4Jason Sams    Element mElement_UCHAR_4;
5317d787b4722eaeb79cab42c36060336e092b77b5fJason Sams
5321d45c47975ab2a8cef6db5a8976276de31e1e8d0Jason Sams    Element mElement_MATRIX_4X4;
5331d45c47975ab2a8cef6db5a8976276de31e1e8d0Jason Sams    Element mElement_MATRIX_3X3;
5341d45c47975ab2a8cef6db5a8976276de31e1e8d0Jason Sams    Element mElement_MATRIX_2X2;
5351d45c47975ab2a8cef6db5a8976276de31e1e8d0Jason Sams
5364d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    Sampler mSampler_CLAMP_NEAREST;
5374d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    Sampler mSampler_CLAMP_LINEAR;
5384d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    Sampler mSampler_CLAMP_LINEAR_MIP_LINEAR;
5394d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    Sampler mSampler_WRAP_NEAREST;
5404d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    Sampler mSampler_WRAP_LINEAR;
5414d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams    Sampler mSampler_WRAP_LINEAR_MIP_LINEAR;
5424d3399337d18ef04116bc8a2e5799274655d0c30Jason Sams
543d36f248eaf06c569010649902df653da1a9e2accAlex Sakhartchouk    ProgramStore mProgramStore_BLEND_NONE_DEPTH_TEST;
544d36f248eaf06c569010649902df653da1a9e2accAlex Sakhartchouk    ProgramStore mProgramStore_BLEND_NONE_DEPTH_NO_DEPTH;
545d36f248eaf06c569010649902df653da1a9e2accAlex Sakhartchouk    ProgramStore mProgramStore_BLEND_NONE_DEPTH_NO_TEST;
546d36f248eaf06c569010649902df653da1a9e2accAlex Sakhartchouk    ProgramStore mProgramStore_BLEND_NONE_DEPTH_NO_WRITE;
547d36f248eaf06c569010649902df653da1a9e2accAlex Sakhartchouk    ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_TEST;
548d36f248eaf06c569010649902df653da1a9e2accAlex Sakhartchouk    ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_NO_DEPTH;
549d36f248eaf06c569010649902df653da1a9e2accAlex Sakhartchouk    ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_NO_TEST;
550d36f248eaf06c569010649902df653da1a9e2accAlex Sakhartchouk    ProgramStore mProgramStore_BLEND_ALPHA_DEPTH_NO_WRITE;
551d36f248eaf06c569010649902df653da1a9e2accAlex Sakhartchouk    ProgramStore mProgramStore_BLEND_ADD_DEPTH_TEST;
552d36f248eaf06c569010649902df653da1a9e2accAlex Sakhartchouk    ProgramStore mProgramStore_BLEND_ADD_DEPTH_NO_DEPTH;
553d36f248eaf06c569010649902df653da1a9e2accAlex Sakhartchouk    ProgramStore mProgramStore_BLEND_ADD_DEPTH_NO_TEST;
554d36f248eaf06c569010649902df653da1a9e2accAlex Sakhartchouk    ProgramStore mProgramStore_BLEND_ADD_DEPTH_NO_WRITE;
555d36f248eaf06c569010649902df653da1a9e2accAlex Sakhartchouk
556d36f248eaf06c569010649902df653da1a9e2accAlex Sakhartchouk    ProgramRaster mProgramRaster_CULL_BACK;
557d36f248eaf06c569010649902df653da1a9e2accAlex Sakhartchouk    ProgramRaster mProgramRaster_CULL_FRONT;
558d36f248eaf06c569010649902df653da1a9e2accAlex Sakhartchouk    ProgramRaster mProgramRaster_CULL_NONE;
55932e09b5891da0174f161d99e2d3ebe67d6efa39cAlex Sakhartchouk
56060aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich    ///////////////////////////////////////////////////////////////////////////////////
56143702d8925c54360ad5f9f66b0d35d61d59f6910Jack Palevich    //
56260aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
563516c31911578db8ce53529483c3ded918ac7dc6bJason Sams    public static class RSMessage implements Runnable {
564516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        protected int[] mData;
565516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        protected int mID;
566516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        public void run() {
567516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        }
568516c31911578db8ce53529483c3ded918ac7dc6bJason Sams    }
569516c31911578db8ce53529483c3ded918ac7dc6bJason Sams    public RSMessage mMessageCallback = null;
570516c31911578db8ce53529483c3ded918ac7dc6bJason Sams
5717d787b4722eaeb79cab42c36060336e092b77b5fJason Sams    public enum Priority {
5727d787b4722eaeb79cab42c36060336e092b77b5fJason Sams        LOW (5),     //ANDROID_PRIORITY_BACKGROUND + 5
5737d787b4722eaeb79cab42c36060336e092b77b5fJason Sams        NORMAL (-4);  //ANDROID_PRIORITY_DISPLAY
5747d787b4722eaeb79cab42c36060336e092b77b5fJason Sams
5757d787b4722eaeb79cab42c36060336e092b77b5fJason Sams        int mID;
5767d787b4722eaeb79cab42c36060336e092b77b5fJason Sams        Priority(int id) {
5777d787b4722eaeb79cab42c36060336e092b77b5fJason Sams            mID = id;
5787d787b4722eaeb79cab42c36060336e092b77b5fJason Sams        }
5797d787b4722eaeb79cab42c36060336e092b77b5fJason Sams    }
5807d787b4722eaeb79cab42c36060336e092b77b5fJason Sams
581771bebb94054d06f97284379c93a2620613513c3Jason Sams    void validate() {
582771bebb94054d06f97284379c93a2620613513c3Jason Sams        if (mContext == 0) {
583771bebb94054d06f97284379c93a2620613513c3Jason Sams            throw new IllegalStateException("Calling RS with no Context active.");
584771bebb94054d06f97284379c93a2620613513c3Jason Sams        }
585771bebb94054d06f97284379c93a2620613513c3Jason Sams    }
586771bebb94054d06f97284379c93a2620613513c3Jason Sams
5877d787b4722eaeb79cab42c36060336e092b77b5fJason Sams    public void contextSetPriority(Priority p) {
5885dbfe93b3f15f3a837836d024958635fd8f9ad14Jason Sams        validate();
5897d787b4722eaeb79cab42c36060336e092b77b5fJason Sams        nContextSetPriority(p.mID);
5907d787b4722eaeb79cab42c36060336e092b77b5fJason Sams    }
5917d787b4722eaeb79cab42c36060336e092b77b5fJason Sams
592704ff64b099406bb328898a7443921f22dbffd6dJason Sams    protected static class MessageThread extends Thread {
593516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        RenderScript mRS;
594516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        boolean mRun = true;
595516c31911578db8ce53529483c3ded918ac7dc6bJason Sams
596516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        MessageThread(RenderScript rs) {
597516c31911578db8ce53529483c3ded918ac7dc6bJason Sams            super("RSMessageThread");
598516c31911578db8ce53529483c3ded918ac7dc6bJason Sams            mRS = rs;
599516c31911578db8ce53529483c3ded918ac7dc6bJason Sams
600516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        }
601516c31911578db8ce53529483c3ded918ac7dc6bJason Sams
602516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        public void run() {
603516c31911578db8ce53529483c3ded918ac7dc6bJason Sams            // This function is a temporary solution.  The final solution will
604516c31911578db8ce53529483c3ded918ac7dc6bJason Sams            // used typed allocations where the message id is the type indicator.
605516c31911578db8ce53529483c3ded918ac7dc6bJason Sams            int[] rbuf = new int[16];
6062e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams            mRS.nContextInitToClient(mRS.mContext);
607516c31911578db8ce53529483c3ded918ac7dc6bJason Sams            while(mRun) {
6081d45c47975ab2a8cef6db5a8976276de31e1e8d0Jason Sams                rbuf[0] = 0;
6092e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams                int msg = mRS.nContextGetMessage(mRS.mContext, rbuf, true);
610ab98bb6e8b95bef7415c1ad239be71f93322fbadStephen Hines                if ((msg == 0)) {
6111d45c47975ab2a8cef6db5a8976276de31e1e8d0Jason Sams                    // Can happen for two reasons
612ab98bb6e8b95bef7415c1ad239be71f93322fbadStephen Hines                    if (rbuf[0] > 0 && mRun) {
6131d45c47975ab2a8cef6db5a8976276de31e1e8d0Jason Sams                        // 1: Buffer needs to be enlarged.
6141d45c47975ab2a8cef6db5a8976276de31e1e8d0Jason Sams                        rbuf = new int[rbuf[0] + 2];
6151d45c47975ab2a8cef6db5a8976276de31e1e8d0Jason Sams                    } else {
6161d45c47975ab2a8cef6db5a8976276de31e1e8d0Jason Sams                        // 2: teardown.
6171d45c47975ab2a8cef6db5a8976276de31e1e8d0Jason Sams                        // But we want to avoid starving other threads during
6181d45c47975ab2a8cef6db5a8976276de31e1e8d0Jason Sams                        // teardown by yielding until the next line in the destructor
6191d45c47975ab2a8cef6db5a8976276de31e1e8d0Jason Sams                        // can execute to set mRun = false
6201d45c47975ab2a8cef6db5a8976276de31e1e8d0Jason Sams                        try {
6211d45c47975ab2a8cef6db5a8976276de31e1e8d0Jason Sams                            sleep(1, 0);
6221d45c47975ab2a8cef6db5a8976276de31e1e8d0Jason Sams                        } catch(InterruptedException e) {
6231d45c47975ab2a8cef6db5a8976276de31e1e8d0Jason Sams                        }
624516c31911578db8ce53529483c3ded918ac7dc6bJason Sams                    }
625ab98bb6e8b95bef7415c1ad239be71f93322fbadStephen Hines                    continue;
626516c31911578db8ce53529483c3ded918ac7dc6bJason Sams                }
627516c31911578db8ce53529483c3ded918ac7dc6bJason Sams                if(mRS.mMessageCallback != null) {
628516c31911578db8ce53529483c3ded918ac7dc6bJason Sams                    mRS.mMessageCallback.mData = rbuf;
629516c31911578db8ce53529483c3ded918ac7dc6bJason Sams                    mRS.mMessageCallback.mID = msg;
630516c31911578db8ce53529483c3ded918ac7dc6bJason Sams                    mRS.mMessageCallback.run();
631516c31911578db8ce53529483c3ded918ac7dc6bJason Sams                }
632516c31911578db8ce53529483c3ded918ac7dc6bJason Sams            }
6333bc47d438171dce294e816366d53bc9eca772c5bJason Sams            Log.d(LOG_TAG, "MessageThread exiting.");
634516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        }
635516c31911578db8ce53529483c3ded918ac7dc6bJason Sams    }
636516c31911578db8ce53529483c3ded918ac7dc6bJason Sams
637704ff64b099406bb328898a7443921f22dbffd6dJason Sams    protected RenderScript() {
63860aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich    }
63960aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
640704ff64b099406bb328898a7443921f22dbffd6dJason Sams    public static RenderScript create() {
641704ff64b099406bb328898a7443921f22dbffd6dJason Sams        RenderScript rs = new RenderScript();
642704ff64b099406bb328898a7443921f22dbffd6dJason Sams
643704ff64b099406bb328898a7443921f22dbffd6dJason Sams        rs.mDev = rs.nDeviceCreate();
644704ff64b099406bb328898a7443921f22dbffd6dJason Sams        rs.mContext = rs.nContextCreate(rs.mDev, 0);
645704ff64b099406bb328898a7443921f22dbffd6dJason Sams        rs.mMessageThread = new MessageThread(rs);
646704ff64b099406bb328898a7443921f22dbffd6dJason Sams        rs.mMessageThread.start();
647704ff64b099406bb328898a7443921f22dbffd6dJason Sams        Element.initPredefined(rs);
648704ff64b099406bb328898a7443921f22dbffd6dJason Sams        return rs;
649efd9b6fb2e0f31b50db089352118e5daeb268879Jason Sams    }
650efd9b6fb2e0f31b50db089352118e5daeb268879Jason Sams
651715333b832fb448c32165c7d97d408a3fa43f7cbJason Sams    public void contextDump(int bits) {
6525dbfe93b3f15f3a837836d024958635fd8f9ad14Jason Sams        validate();
653715333b832fb448c32165c7d97d408a3fa43f7cbJason Sams        nContextDump(bits);
654715333b832fb448c32165c7d97d408a3fa43f7cbJason Sams    }
655715333b832fb448c32165c7d97d408a3fa43f7cbJason Sams
65696ed4cfa62dd09aafb3f9da01e047661b4fe3c95Jason Sams    public void finish() {
65796ed4cfa62dd09aafb3f9da01e047661b4fe3c95Jason Sams        nContextFinish();
65896ed4cfa62dd09aafb3f9da01e047661b4fe3c95Jason Sams    }
65996ed4cfa62dd09aafb3f9da01e047661b4fe3c95Jason Sams
660f5b4596a383b6ab83f92edecfe054e80b555c2d0Jason Sams    public void destroy() {
6615dbfe93b3f15f3a837836d024958635fd8f9ad14Jason Sams        validate();
6622e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        nContextDeinitToClient(mContext);
663516c31911578db8ce53529483c3ded918ac7dc6bJason Sams        mMessageThread.mRun = false;
664a8bf9429b29743b3489817feb21bde2416acc465Jason Sams        try {
665a8bf9429b29743b3489817feb21bde2416acc465Jason Sams            mMessageThread.join();
666a8bf9429b29743b3489817feb21bde2416acc465Jason Sams        } catch(InterruptedException e) {
667a8bf9429b29743b3489817feb21bde2416acc465Jason Sams        }
668516c31911578db8ce53529483c3ded918ac7dc6bJason Sams
6692e1872fe07cf8952812a417985e6e1f61bdeab5dJason Sams        nContextDestroy();
670f5b4596a383b6ab83f92edecfe054e80b555c2d0Jason Sams        mContext = 0;
671f5b4596a383b6ab83f92edecfe054e80b555c2d0Jason Sams
672f5b4596a383b6ab83f92edecfe054e80b555c2d0Jason Sams        nDeviceDestroy(mDev);
673f5b4596a383b6ab83f92edecfe054e80b555c2d0Jason Sams        mDev = 0;
674f5b4596a383b6ab83f92edecfe054e80b555c2d0Jason Sams    }
67502fb2cb531035779a25dbf9595e0628ea40585b0Jason Sams
676a9e7a05b84470257637c97d65f6562aa832c66efJason Sams    boolean isAlive() {
677a9e7a05b84470257637c97d65f6562aa832c66efJason Sams        return mContext != 0;
678a9e7a05b84470257637c97d65f6562aa832c66efJason Sams    }
679a9e7a05b84470257637c97d65f6562aa832c66efJason Sams
68060aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich    ///////////////////////////////////////////////////////////////////////////////////
68160aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich    // Root state
68260aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
683704ff64b099406bb328898a7443921f22dbffd6dJason Sams    protected int safeID(BaseObj o) {
6846b9dec00afec359f091ed353f371f08ff150278aJason Sams        if(o != null) {
6856b9dec00afec359f091ed353f371f08ff150278aJason Sams            return o.mID;
686d8e4161f114331343b897cbacea927e7e60e7b17Jason Sams        }
6876b9dec00afec359f091ed353f371f08ff150278aJason Sams        return 0;
68860aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich    }
68960aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich}
69060aa3eaf559b1410898c228e4f6ab7920f3953d0Jack Palevich
69136e612a488511940b61f09803b270aa1c61b68e0Jason Sams
69280a4c2cd34aedb4f1a2e5e7d1ac26a9aeebe41aeAlex Sakhartchouk
693