Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit da214787 authored by Android (Google) Code Review's avatar Android (Google) Code Review
Browse files

Merge change 24024 into eclair

* changes:
  Remove "predefined" elements from Java layer.  Static elements continue to exist but are no longer treated as a special version of element.
parents ff86d9f9 ea84a7c5
Loading
Loading
Loading
Loading
+7 −18
Original line number Diff line number Diff line
@@ -209,35 +209,24 @@ public class Allocation extends BaseObj {
    static public Allocation createSized(RenderScript rs, Element e, int count)
        throws IllegalArgumentException {

        int id;
        if(e.mIsPredefined) {
            id = rs.nAllocationCreatePredefSized(e.mPredefinedID, count);
        } else {
            id = rs.nAllocationCreateSized(e.mID, count);
        int id = rs.nAllocationCreateSized(e.mID, count);
        if(id == 0) {
            throw new IllegalStateException("Bad element.");
        }
        }
        return new Allocation(id, rs, null);
    }

    static public Allocation createFromBitmap(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips)
        throws IllegalArgumentException {
        if(!dstFmt.mIsPredefined) {
            throw new IllegalStateException("Attempting to allocate a bitmap with a non-static element.");
        }

        int id = rs.nAllocationCreateFromBitmap(dstFmt.mPredefinedID, genMips, b);
        int id = rs.nAllocationCreateFromBitmap(dstFmt.mID, genMips, b);
        return new Allocation(id, rs, null);
    }

    static public Allocation createFromBitmapBoxed(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips)
        throws IllegalArgumentException {
        if(!dstFmt.mIsPredefined) {
            throw new IllegalStateException("Attempting to allocate a bitmap with a non-static element.");
        }

        int id = rs.nAllocationCreateFromBitmapBoxed(dstFmt.mPredefinedID, genMips, b);
        int id = rs.nAllocationCreateFromBitmapBoxed(dstFmt.mID, genMips, b);
        return new Allocation(id, rs, null);
    }

@@ -250,7 +239,7 @@ public class Allocation extends BaseObj {
            is = res.openRawResource(id, value);

            int asset = ((AssetManager.AssetInputStream) is).getAssetInt();
            int allocationId = rs.nAllocationCreateFromAssetStream(dstFmt.mPredefinedID, genMips,
            int allocationId = rs.nAllocationCreateFromAssetStream(dstFmt.mID, genMips,
                    asset);

            return new Allocation(allocationId, rs, null);
+197 −113
Original line number Diff line number Diff line
@@ -23,62 +23,171 @@ import java.lang.reflect.Field;
 *
 **/
public class Element extends BaseObj {
    final int mPredefinedID;
    final boolean mIsPredefined;
    final int mSize;

    public static final Element USER_U8 = new Element(0, 1);
    public static final Element USER_I8 = new Element(1, 1);
    public static final Element USER_U16 = new Element(2, 2);
    public static final Element USER_I16 = new Element(3, 2);
    public static final Element USER_U32 = new Element(4, 4);
    public static final Element USER_I32 = new Element(5, 4);
    public static final Element USER_FLOAT = new Element(6, 4);

    public static final Element A_8 = new Element(7, 1);
    public static final Element RGB_565 = new Element(8, 2);
    public static final Element RGB_888 = new Element(11, 2);
    public static final Element RGBA_5551 = new Element(9, 2);
    public static final Element RGBA_4444 = new Element(10, 2);
    public static final Element RGBA_8888 = new Element(12, 4);

    public static final Element INDEX_16 = new Element(13, 2);
    public static final Element INDEX_32 = new Element(14, 2);
    public static final Element XY_F32 = new Element(15, 8);
    public static final Element XYZ_F32 = new Element(16, 12);
    public static final Element ST_XY_F32 = new Element(17, 16);
    public static final Element ST_XYZ_F32 = new Element(18, 20);
    public static final Element NORM_XYZ_F32 = new Element(19, 24);
    public static final Element NORM_ST_XYZ_F32 = new Element(20, 32);

    void initPredef(RenderScript rs) {
        mID = rs.nElementGetPredefined(mPredefinedID);
    }

    static void init(RenderScript rs) {
        USER_U8.initPredef(rs);
        USER_I8.initPredef(rs);
        USER_U16.initPredef(rs);
        USER_I16.initPredef(rs);
        USER_U32.initPredef(rs);
        USER_I32.initPredef(rs);
        USER_FLOAT.initPredef(rs);

        A_8.initPredef(rs);
        RGB_565.initPredef(rs);
        RGB_888.initPredef(rs);
        RGBA_5551.initPredef(rs);
        RGBA_4444.initPredef(rs);
        RGBA_8888.initPredef(rs);

        INDEX_16.initPredef(rs);
        INDEX_32.initPredef(rs);
        XY_F32.initPredef(rs);
        XYZ_F32.initPredef(rs);
        ST_XY_F32.initPredef(rs);
        ST_XYZ_F32.initPredef(rs);
        NORM_XYZ_F32.initPredef(rs);
        NORM_ST_XYZ_F32.initPredef(rs);
    int mSize;
    Entry[] mEntries;

    static class Entry {
        Element mElement;
        Element.DataType mType;
        Element.DataKind mKind;
        boolean mIsNormalized;
        int mBits;
        String mName;

        Entry(Element e, int bits) {
            mElement = e;
            int mBits = bits;
        }

        Entry(DataType dt, DataKind dk, boolean isNorm, int bits, String name) {
            mType = dt;
            mKind = dk;
            mIsNormalized = isNorm;
            mBits = bits;
            mName = name;
        }
    }

    public static final Element USER_U8 = new Element();
    public static final Element USER_I8 = new Element();
    public static final Element USER_U16 = new Element();
    public static final Element USER_I16 = new Element();
    public static final Element USER_U32 = new Element();
    public static final Element USER_I32 = new Element();
    public static final Element USER_FLOAT = new Element();

    public static final Element A_8 = new Element();
    public static final Element RGB_565 = new Element();
    public static final Element RGB_888 = new Element();
    public static final Element RGBA_5551 = new Element();
    public static final Element RGBA_4444 = new Element();
    public static final Element RGBA_8888 = new Element();

    public static final Element INDEX_16 = new Element();
    public static final Element XY_F32 = new Element();
    public static final Element XYZ_F32 = new Element();
    public static final Element ST_XY_F32 = new Element();
    public static final Element ST_XYZ_F32 = new Element();
    public static final Element NORM_XYZ_F32 = new Element();
    public static final Element NORM_ST_XYZ_F32 = new Element();

    static void initPredefined(RenderScript rs) {
        USER_U8.mEntries = new Entry[1];
        USER_U8.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.USER, false, 8, null);
        USER_U8.init(rs);

        USER_I8.mEntries = new Entry[1];
        USER_I8.mEntries[0] = new Entry(DataType.SIGNED, DataKind.USER, false, 8, null);
        USER_I8.init(rs);

        USER_U16.mEntries = new Entry[1];
        USER_U16.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.USER, false, 16, null);
        USER_U16.init(rs);

        USER_I16.mEntries = new Entry[1];
        USER_I16.mEntries[0] = new Entry(DataType.SIGNED, DataKind.USER, false, 16, null);
        USER_I16.init(rs);

        USER_U32.mEntries = new Entry[1];
        USER_U32.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.USER, false, 32, null);
        USER_U32.init(rs);

        USER_I32.mEntries = new Entry[1];
        USER_I32.mEntries[0] = new Entry(DataType.SIGNED, DataKind.USER, false, 32, null);
        USER_I32.init(rs);

        USER_FLOAT.mEntries = new Entry[1];
        USER_FLOAT.mEntries[0] = new Entry(DataType.FLOAT, DataKind.USER, false, 32, null);
        USER_FLOAT.init(rs);

        A_8.mEntries = new Entry[1];
        A_8.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.ALPHA, true, 8, "a");
        A_8.init(rs);

        RGB_565.mEntries = new Entry[3];
        RGB_565.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.RED, true, 5, "r");
        RGB_565.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.GREEN, true, 6, "g");
        RGB_565.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.BLUE, true, 5, "b");
        RGB_565.init(rs);

        RGB_888.mEntries = new Entry[3];
        RGB_888.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.RED, true, 8, "r");
        RGB_888.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.GREEN, true, 8, "g");
        RGB_888.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.BLUE, true, 8, "b");
        RGB_888.init(rs);

        RGBA_5551.mEntries = new Entry[4];
        RGBA_5551.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.RED, true, 5, "r");
        RGBA_5551.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.GREEN, true, 5, "g");
        RGBA_5551.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.BLUE, true, 5, "b");
        RGBA_5551.mEntries[3] = new Entry(DataType.UNSIGNED, DataKind.ALPHA, true, 1, "a");
        RGBA_5551.init(rs);

        RGBA_4444.mEntries = new Entry[4];
        RGBA_4444.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.RED, true, 4, "r");
        RGBA_4444.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.GREEN, true, 4, "g");
        RGBA_4444.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.BLUE, true, 4, "b");
        RGBA_4444.mEntries[3] = new Entry(DataType.UNSIGNED, DataKind.ALPHA, true, 4, "a");
        RGBA_4444.init(rs);

        RGBA_8888.mEntries = new Entry[4];
        RGBA_8888.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.RED, true, 8, "r");
        RGBA_8888.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.GREEN, true, 8, "g");
        RGBA_8888.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.BLUE, true, 8, "b");
        RGBA_8888.mEntries[3] = new Entry(DataType.UNSIGNED, DataKind.ALPHA, true, 8, "a");
        RGBA_8888.init(rs);

        INDEX_16.mEntries = new Entry[1];
        INDEX_16.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.INDEX, false, 16, "index");
        INDEX_16.init(rs);

        XY_F32.mEntries = new Entry[2];
        XY_F32.mEntries[0] = new Entry(DataType.FLOAT, DataKind.X, false, 32, "x");
        XY_F32.mEntries[1] = new Entry(DataType.FLOAT, DataKind.Y, false, 32, "y");
        XY_F32.init(rs);

        XYZ_F32.mEntries = new Entry[3];
        XYZ_F32.mEntries[0] = new Entry(DataType.FLOAT, DataKind.X, false, 32, "x");
        XYZ_F32.mEntries[1] = new Entry(DataType.FLOAT, DataKind.Y, false, 32, "y");
        XYZ_F32.mEntries[2] = new Entry(DataType.FLOAT, DataKind.Z, false, 32, "z");
        XYZ_F32.init(rs);

        ST_XY_F32.mEntries = new Entry[4];
        ST_XY_F32.mEntries[0] = new Entry(DataType.FLOAT, DataKind.S, false, 32, "s");
        ST_XY_F32.mEntries[1] = new Entry(DataType.FLOAT, DataKind.T, false, 32, "t");
        ST_XY_F32.mEntries[2] = new Entry(DataType.FLOAT, DataKind.X, false, 32, "x");
        ST_XY_F32.mEntries[3] = new Entry(DataType.FLOAT, DataKind.Y, false, 32, "y");
        ST_XY_F32.init(rs);

        ST_XYZ_F32.mEntries = new Entry[5];
        ST_XYZ_F32.mEntries[0] = new Entry(DataType.FLOAT, DataKind.S, false, 32, "s");
        ST_XYZ_F32.mEntries[1] = new Entry(DataType.FLOAT, DataKind.T, false, 32, "t");
        ST_XYZ_F32.mEntries[2] = new Entry(DataType.FLOAT, DataKind.X, false, 32, "x");
        ST_XYZ_F32.mEntries[3] = new Entry(DataType.FLOAT, DataKind.Y, false, 32, "y");
        ST_XYZ_F32.mEntries[4] = new Entry(DataType.FLOAT, DataKind.Z, false, 32, "z");
        ST_XYZ_F32.init(rs);

        NORM_XYZ_F32.mEntries = new Entry[6];
        NORM_XYZ_F32.mEntries[0] = new Entry(DataType.FLOAT, DataKind.NX, false, 32, "nx");
        NORM_XYZ_F32.mEntries[1] = new Entry(DataType.FLOAT, DataKind.NY, false, 32, "ny");
        NORM_XYZ_F32.mEntries[2] = new Entry(DataType.FLOAT, DataKind.NZ, false, 32, "nz");
        NORM_XYZ_F32.mEntries[3] = new Entry(DataType.FLOAT, DataKind.X, false, 32, "x");
        NORM_XYZ_F32.mEntries[4] = new Entry(DataType.FLOAT, DataKind.Y, false, 32, "y");
        NORM_XYZ_F32.mEntries[5] = new Entry(DataType.FLOAT, DataKind.Z, false, 32, "z");
        NORM_XYZ_F32.init(rs);

        NORM_ST_XYZ_F32.mEntries = new Entry[8];
        NORM_ST_XYZ_F32.mEntries[0] = new Entry(DataType.FLOAT, DataKind.NX, false, 32, "nx");
        NORM_ST_XYZ_F32.mEntries[1] = new Entry(DataType.FLOAT, DataKind.NY, false, 32, "ny");
        NORM_ST_XYZ_F32.mEntries[2] = new Entry(DataType.FLOAT, DataKind.NZ, false, 32, "nz");
        NORM_ST_XYZ_F32.mEntries[3] = new Entry(DataType.FLOAT, DataKind.S, false, 32, "s");
        NORM_ST_XYZ_F32.mEntries[4] = new Entry(DataType.FLOAT, DataKind.T, false, 32, "t");
        NORM_ST_XYZ_F32.mEntries[5] = new Entry(DataType.FLOAT, DataKind.X, false, 32, "x");
        NORM_ST_XYZ_F32.mEntries[6] = new Entry(DataType.FLOAT, DataKind.Y, false, 32, "y");
        NORM_ST_XYZ_F32.mEntries[7] = new Entry(DataType.FLOAT, DataKind.Z, false, 32, "z");
        NORM_ST_XYZ_F32.init(rs);

        rs.nInitElements(A_8.mID, RGBA_4444.mID, RGBA_8888.mID, RGB_565.mID);
    }


@@ -121,27 +230,13 @@ public class Element extends BaseObj {
        }
    }


    Element(int predef, int size) {
    Element() {
        super(null);
        mID = 0;
        mPredefinedID = predef;
        mIsPredefined = true;
        mSize = size;
    }

    Element(int id, RenderScript rs, int size) {
        super(rs);
        mID = id;
        mPredefinedID = 0;
        mIsPredefined = false;
        mSize = size;
        mSize = 0;
    }

    public void destroy() throws IllegalStateException {
        if(mIsPredefined) {
            throw new IllegalStateException("Attempting to destroy a predefined Element.");
        }
        super.destroy();
    }

@@ -166,27 +261,41 @@ public class Element extends BaseObj {
        return b.create();
    }

    static synchronized void internalCreate(RenderScript rs, Element e) {
        rs.nElementBegin();
        int bits = 0;
        for (int ct=0; ct < e.mEntries.length; ct++) {
            Entry en = e.mEntries[ct];
            if(en.mElement !=  null) {
                //rs.nElementAdd(en.mElement.mID);
            } else {
                int norm = 0;
                if (en.mIsNormalized) {
                    norm = 1;
                }
                rs.nElementAdd(en.mKind.mID, en.mType.mID, norm, en.mBits, en.mName);
                bits += en.mBits;
            }
        }
        e.mID = rs.nElementCreate();
        e.mSize = (bits + 7) >> 3;
    }

    void init(RenderScript rs) {
        mRS = rs;
        internalCreate(mRS, this);
    }


    public static class Builder {
        RenderScript mRS;
        Entry[] mEntries;
        int mEntryCount;
        int mSizeBits;

        private class Entry {
            Element mElement;
            Element.DataType mType;
            Element.DataKind mKind;
            boolean mIsNormalized;
            int mBits;
            String mName;
        }

        public Builder(RenderScript rs) {
            mRS = rs;
            mEntryCount = 0;
            mEntries = new Entry[8];
            mSizeBits = 0;
        }

        void addEntry(Entry e) {
@@ -200,24 +309,13 @@ public class Element extends BaseObj {
        }

        public Builder add(Element e) throws IllegalArgumentException {
            if(!e.mIsPredefined) {
                throw new IllegalArgumentException("add requires a predefined Element.");
            }
            Entry en = new Entry();
            en.mElement = e;
            Entry en = new Entry(e, e.mSize * 8);
            addEntry(en);
            mSizeBits += e.mSize * 8;
            return this;
        }

        public Builder add(Element.DataType dt, Element.DataKind dk, boolean isNormalized, int bits, String name) {
            Entry en = new Entry();
            en.mType = dt;
            en.mKind = dk;
            en.mIsNormalized = isNormalized;
            en.mBits = bits;
            en.mName = name;
            mSizeBits += bits;
            Entry en = new Entry(dt, dk, isNormalized, bits, name);
            addEntry(en);
            return this;
        }
@@ -345,26 +443,12 @@ public class Element extends BaseObj {
            return this;
        }

        static synchronized Element internalCreate(RenderScript rs, Builder b) {
            rs.nElementBegin();
            for (int ct=0; ct < b.mEntryCount; ct++) {
                Entry en = b.mEntries[ct];
                if(en.mElement !=  null) {
                    rs.nElementAddPredefined(en.mElement.mPredefinedID);
                } else {
                    int norm = 0;
                    if (en.mIsNormalized) {
                        norm = 1;
                    }
                    rs.nElementAdd(en.mKind.mID, en.mType.mID, norm, en.mBits, en.mName);
                }
            }
            int id = rs.nElementCreate();
            return new Element(id, rs, (b.mSizeBits + 7) >> 3);
        }

        public Element create() {
            return internalCreate(mRS, this);
            Element e = new Element();
            e.mEntries = new Entry[mEntryCount];
            java.lang.System.arraycopy(mEntries, 0, e.mEntries, 0, mEntryCount);
            e.init(mRS);
            return e;
        }
    }

+3 −5
Original line number Diff line number Diff line
@@ -57,6 +57,8 @@ public class RenderScript {
        }
    }

    native void nInitElements(int a8, int rgba4444, int rgba8888, int rgb565);

    native int  nDeviceCreate();
    native void nDeviceDestroy(int dev);
    native int  nContextCreate(int dev, Surface sur, int ver, boolean useDepth);
@@ -78,10 +80,8 @@ public class RenderScript {
    native int  nFileOpen(byte[] name);

    native void nElementBegin();
    native void nElementAddPredefined(int predef);
    native void nElementAdd(int kind, int type, int norm, int bits, String s);
    native int  nElementCreate();
    native int  nElementGetPredefined(int predef);

    native void nTypeBegin(int elementID);
    native void nTypeAdd(int dim, int val);
@@ -90,7 +90,6 @@ public class RenderScript {
    native void nTypeSetupFields(Type t, int[] types, int[] bits, Field[] IDs);

    native int  nAllocationCreateTyped(int type);
    native int  nAllocationCreatePredefSized(int predef, int count);
    native int  nAllocationCreateSized(int elem, int count);
    native int  nAllocationCreateFromBitmap(int dstFmt, boolean genMips, Bitmap bmp);
    native int  nAllocationCreateFromBitmapBoxed(int dstFmt, boolean genMips, Bitmap bmp);
@@ -203,7 +202,7 @@ public class RenderScript {

        // TODO: This should be protected by a lock
        if(!mElementsInitialized) {
            Element.init(this);
            Element.initPredefined(this);
            mElementsInitialized = true;
        }
    }
@@ -227,7 +226,6 @@ public class RenderScript {
    }

    public void triangleMeshBegin(Element vertex, Element index) {
        Log.e("rs", "vtx " + vertex.toString() + "  " + vertex.mID + "  " + vertex.mPredefinedID);
        nTriangleMeshBegin(vertex.mID, index.mID);
    }

+29 −42
Original line number Diff line number Diff line
@@ -58,6 +58,11 @@ static jfieldID gContextId = 0;
static jfieldID gNativeBitmapID = 0;
static jfieldID gTypeNativeCache = 0;

static RsElement g_A_8 = NULL;
static RsElement g_RGBA_4444 = NULL;
static RsElement g_RGBA_8888 = NULL;
static RsElement g_RGB_565 = NULL;

static void _nInit(JNIEnv *_env, jclass _this)
{
    gContextId             = _env->GetFieldID(_this, "mContext", "I");
@@ -69,6 +74,13 @@ static void _nInit(JNIEnv *_env, jclass _this)
    gTypeNativeCache = _env->GetFieldID(typeClass, "mNativeCache", "I");
}

static void nInitElements(JNIEnv *_env, jobject _this, jint a8, jint rgba4444, jint rgba8888, jint rgb565)
{
    g_A_8 = reinterpret_cast<RsElement>(a8);
    g_RGBA_4444 = reinterpret_cast<RsElement>(rgba4444);
    g_RGBA_8888 = reinterpret_cast<RsElement>(rgba8888);
    g_RGB_565 = reinterpret_cast<RsElement>(rgb565);
}

// ---------------------------------------------------------------------------

@@ -167,13 +179,6 @@ nElementBegin(JNIEnv *_env, jobject _this)
    rsElementBegin(con);
}

static void
nElementAddPredefined(JNIEnv *_env, jobject _this, jint predef)
{
    RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
    LOG_API("nElementAddPredefined, con(%p), predef(%i)", con, predef);
    rsElementAddPredefined(con, (RsElementPredefined)predef);
}

static void
nElementAdd(JNIEnv *_env, jobject _this, jint kind, jint type, jint norm, jint bits, jstring name)
@@ -198,14 +203,6 @@ nElementCreate(JNIEnv *_env, jobject _this)
    return (jint)rsElementCreate(con);
}

static jint
nElementGetPredefined(JNIEnv *_env, jobject _this, jint predef)
{
    RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
    LOG_API("nElementGetPredefined, con(%p) predef(%i)", con, predef);
    return (jint)rsElementGetPredefined(con, (RsElementPredefined)predef);
}

// -----------------------------------

static void
@@ -327,14 +324,6 @@ nAllocationCreateTyped(JNIEnv *_env, jobject _this, jint e)
    return (jint) rsAllocationCreateTyped(con, (RsElement)e);
}

static jint
nAllocationCreatePredefSized(JNIEnv *_env, jobject _this, jint predef, jint count)
{
    RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
    LOG_API("nAllocationCreatePredefSized, con(%p), predef(%i), count(%i)", con, predef, count);
    return (jint) rsAllocationCreatePredefSized(con, (RsElementPredefined)predef, count);
}

static jint
nAllocationCreateSized(JNIEnv *_env, jobject _this, jint e, jint count)
{
@@ -359,24 +348,24 @@ nAllocationUploadToBufferObject(JNIEnv *_env, jobject _this, jint a)
    rsAllocationUploadToBufferObject(con, (RsAllocation)a);
}

static RsElementPredefined SkBitmapToPredefined(SkBitmap::Config cfg)
static RsElement SkBitmapToPredefined(SkBitmap::Config cfg)
{
    switch (cfg) {
    case SkBitmap::kA8_Config:
        return RS_ELEMENT_A_8;
        return g_A_8;
    case SkBitmap::kARGB_4444_Config:
        return RS_ELEMENT_RGBA_4444;
        return g_RGBA_4444;
    case SkBitmap::kARGB_8888_Config:
        return RS_ELEMENT_RGBA_8888;
        return g_RGBA_8888;
    case SkBitmap::kRGB_565_Config:
        return RS_ELEMENT_RGB_565;
        return g_RGB_565;

    default:
        break;
    }
    // If we don't have a conversion mark it as a user type.
    LOGE("Unsupported bitmap type");
    return RS_ELEMENT_USER_U8;
    return NULL;
}

static int
@@ -388,14 +377,13 @@ nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jint dstFmt, jboolean g
    const SkBitmap& bitmap(*nativeBitmap);
    SkBitmap::Config config = bitmap.getConfig();

    RsElementPredefined e = SkBitmapToPredefined(config);

    if (e != RS_ELEMENT_USER_U8) {
    RsElement e = SkBitmapToPredefined(config);
    if (e) {
        bitmap.lockPixels();
        const int w = bitmap.width();
        const int h = bitmap.height();
        const void* ptr = bitmap.getPixels();
        jint id = (jint)rsAllocationCreateFromBitmap(con, w, h, (RsElementPredefined)dstFmt, e, genMips, ptr);
        jint id = (jint)rsAllocationCreateFromBitmap(con, w, h, (RsElement)dstFmt, e, genMips, ptr);
        bitmap.unlockPixels();
        return id;
    }
@@ -414,14 +402,14 @@ nAllocationCreateFromAssetStream(JNIEnv *_env, jobject _this, jint dstFmt, jbool

    SkBitmap::Config config = bitmap.getConfig();

    RsElementPredefined e = SkBitmapToPredefined(config);
    RsElement e = SkBitmapToPredefined(config);

    if (e != RS_ELEMENT_USER_U8) {
    if (e) {
        bitmap.lockPixels();
        const int w = bitmap.width();
        const int h = bitmap.height();
        const void* ptr = bitmap.getPixels();
        jint id = (jint)rsAllocationCreateFromBitmap(con, w, h, (RsElementPredefined)dstFmt, e, genMips, ptr);
        jint id = (jint)rsAllocationCreateFromBitmap(con, w, h, (RsElement)dstFmt, e, genMips, ptr);
        bitmap.unlockPixels();
        return id;
    }
@@ -437,14 +425,14 @@ nAllocationCreateFromBitmapBoxed(JNIEnv *_env, jobject _this, jint dstFmt, jbool
    const SkBitmap& bitmap(*nativeBitmap);
    SkBitmap::Config config = bitmap.getConfig();

    RsElementPredefined e = SkBitmapToPredefined(config);
    RsElement e = SkBitmapToPredefined(config);

    if (e != RS_ELEMENT_USER_U8) {
    if (e) {
        bitmap.lockPixels();
        const int w = bitmap.width();
        const int h = bitmap.height();
        const void* ptr = bitmap.getPixels();
        jint id = (jint)rsAllocationCreateFromBitmapBoxed(con, w, h, (RsElementPredefined)dstFmt, e, genMips, ptr);
        jint id = (jint)rsAllocationCreateFromBitmapBoxed(con, w, h, (RsElement)dstFmt, e, genMips, ptr);
        bitmap.unlockPixels();
        return id;
    }
@@ -1244,6 +1232,8 @@ static const char *classPathName = "android/renderscript/RenderScript";

static JNINativeMethod methods[] = {
{"_nInit",                         "()V",                                  (void*)_nInit },
{"nInitElements",                  "(IIII)V",                              (void*)nInitElements },

{"nDeviceCreate",                  "()I",                                  (void*)nDeviceCreate },
{"nDeviceDestroy",                 "(I)V",                                 (void*)nDeviceDestroy },
{"nContextCreate",                 "(ILandroid/view/Surface;IZ)I",         (void*)nContextCreate },
@@ -1255,10 +1245,8 @@ static JNINativeMethod methods[] = {
{"nFileOpen",                      "([B)I",                                (void*)nFileOpen },

{"nElementBegin",                  "()V",                                  (void*)nElementBegin },
{"nElementAddPredefined",          "(I)V",                                 (void*)nElementAddPredefined },
{"nElementAdd",                    "(IIIILjava/lang/String;)V",            (void*)nElementAdd },
{"nElementCreate",                 "()I",                                  (void*)nElementCreate },
{"nElementGetPredefined",          "(I)I",                                 (void*)nElementGetPredefined },

{"nTypeBegin",                     "(I)V",                                 (void*)nTypeBegin },
{"nTypeAdd",                       "(II)V",                                (void*)nTypeAdd },
@@ -1267,7 +1255,6 @@ static JNINativeMethod methods[] = {
{"nTypeSetupFields",               "(Landroid/renderscript/Type;[I[I[Ljava/lang/reflect/Field;)V", (void*)nTypeSetupFields },

{"nAllocationCreateTyped",         "(I)I",                                 (void*)nAllocationCreateTyped },
{"nAllocationCreatePredefSized",   "(II)I",                                (void*)nAllocationCreatePredefSized },
{"nAllocationCreateSized",         "(II)I",                                (void*)nAllocationCreateSized },
{"nAllocationCreateFromBitmap",    "(IZLandroid/graphics/Bitmap;)I",       (void*)nAllocationCreateFromBitmap },
{"nAllocationCreateFromBitmapBoxed","(IZLandroid/graphics/Bitmap;)I",      (void*)nAllocationCreateFromBitmapBoxed },
+38 −74

File changed.

Preview size limit exceeded, changes collapsed.

Loading