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

Commit fe08d997 authored by Jason Sams's avatar Jason Sams
Browse files

Implement first pass bitmap to allocation support. The Java bindings can...

Implement first pass bitmap to allocation support.  The Java bindings can create a 2D allocation by passing in a Bitmap object.
parent cc77841f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -86,6 +86,7 @@ enum RsElementPredefined {
    RS_ELEMENT_USER_I32,
    RS_ELEMENT_USER_FLOAT, 

    RS_ELEMENT_A_8, 
    RS_ELEMENT_RGB_565, 
    RS_ELEMENT_RGBA_5551, 
    RS_ELEMENT_RGBA_4444, 
+10 −6
Original line number Diff line number Diff line
@@ -58,9 +58,6 @@ typedef struct {

    void (*color)(void *con, float r, float g, float b, float a);

    void (*renderTriangleMesh)(void *con, RsTriangleMesh);
    void (*renderTriangleMeshRange)(void *con, RsTriangleMesh, uint32_t start, uint32_t count);

    void (*programFragmentBindTexture)(void *con, RsProgramFragment, uint32_t slot, RsAllocation);
    void (*programFragmentBindSampler)(void *con, RsProgramFragment, uint32_t slot, RsAllocation);

@@ -76,11 +73,18 @@ typedef struct {

    uint32_t (*rand)(void *con, uint32_t max);

    void (*contextBindProgramFragment)(void *con, RsProgramFragment pf);
    void (*contextBindProgramFragmentStore)(void *con, RsProgramFragmentStore pfs);


    // Drawing funcs
    void (*renderTriangleMesh)(void *con, RsTriangleMesh);
    void (*renderTriangleMeshRange)(void *con, RsTriangleMesh, uint32_t start, uint32_t count);

    // Assumes (GL_FIXED) x,y,z (GL_UNSIGNED_BYTE)r,g,b,a
    void (*drawTriangleArray)(void *con, RsAllocation alloc, uint32_t count);

    void (*contextBindProgramFragment)(void *con, RsProgramFragment pf);
    void (*contextBindProgramFragmentStore)(void *con, RsProgramFragmentStore pfs);
    void (*drawRect)(void *con, int32_t x1, int32_t x2, int32_t y1, int32_t y2);
} rsc_FunctionTable;

typedef void (*rsc_RunScript)(void *con, const rsc_FunctionTable *, uint32_t launchID);
+57 −18
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ import android.view.MenuItem;
import android.view.Window;
import android.view.View;
import android.view.Surface;
import android.graphics.Bitmap;
import android.graphics.Color;

public class RenderScript {
    private static final String LOG_TAG = "libRS_jni";
@@ -79,6 +81,8 @@ public class RenderScript {
    native private int  nAllocationCreateTyped(int type);
    native private int  nAllocationCreatePredefSized(int predef, int count);
    native private int  nAllocationCreateSized(int elem, int count);
    native private int  nAllocationCreateFromBitmap(int w, int h, int dstFmt, int srcFmt, boolean genMips, int[] data);

    //native private int  nAllocationCreateFromBitmap(type.mID);
    native private void nAllocationUploadToTexture(int alloc, int baseMioLevel);
    native private void nAllocationDestroy(int alloc);
@@ -180,20 +184,21 @@ public class RenderScript {
        USER_I32 (5),
        USER_FLOAT (6),

        RGB_565 (7),
        RGBA_5551 (8),
        RGBA_4444 (9),
        RGB_888 (10),
        RGBA_8888 (11),

        INDEX_16 (12),
        INDEX_32 (13),
        XY_F32 (14),
        XYZ_F32 (15),
        ST_XY_F32 (16),
        ST_XYZ_F32 (17),
        NORM_XYZ_F32 (18),
        NORM_ST_XYZ_F32 (19);
        A_8 (7),
        RGB_565 (8),
        RGBA_5551 (9),
        RGBA_4444 (10),
        RGB_888 (11),
        RGBA_8888 (12),

        INDEX_16 (13),
        INDEX_32 (14),
        XY_F32 (15),
        XYZ_F32 (16),
        ST_XY_F32 (17),
        ST_XYZ_F32 (18),
        NORM_XYZ_F32 (19),
        NORM_ST_XYZ_F32 (20);

        int mID;
        ElementPredefined(int id) {
@@ -435,10 +440,44 @@ public class RenderScript {
        return new Allocation(id);
    }

    //public Allocation allocationCreateFromBitmap(string file, boolean genMips) {
        //int id = nAllocationCreateTyped(type.mID);
        //return new Allocation(id);
    //}
    public Allocation allocationCreateFromBitmap(Bitmap b, ElementPredefined dstFmt, boolean genMips) {
        int w = b.getWidth();
        int h = b.getHeight();
        int[] data = new int[w * h];

        int outPtr = 0;
        for(int y=0; y < h; y++) {
            for(int x=0; x < w; x++) {
                data[outPtr] = b.getPixel(x, y);
                outPtr++;
            }
        }

        int srcFmt = 0;
        /*
        switch(b.getConfig()) {
        case ALPHA_8:
            srcFmt = ElementPredefined.A_8.mID;
            break;
        case ARGB_4444:
            srcFmt = ElementPredefined.RGBA_4444.mID;
            break;
        case ARGB_8888:
            srcFmt = ElementPredefined.RGBA_8888.mID;
            break;
        case RGB_565:
            srcFmt = ElementPredefined.RGB_565.mID;
            break;
        default:
            Log.e(LOG_TAG, "allocationCreateFromBitmap, unknown bitmap format");
        } 
        */ 

        srcFmt = ElementPredefined.RGBA_8888.mID;

        int id = nAllocationCreateFromBitmap(w, h, dstFmt.mID, srcFmt, genMips, data);
        return new Allocation(id);
    }

    //////////////////////////////////////////////////////////////////////////////////
    // Adapter1D
+20 −1
Original line number Diff line number Diff line
@@ -195,6 +195,10 @@ void test_script(void *con, const rsc_FunctionTable *ft, uint32_t launchID)
        }
    }

    ft->contextBindProgramFragment(con, (RsProgramFragment)ft->loadEnvI32(con, 0, 7));
    ft->drawRect(con, 0, 256, 0, 512);
    ft->contextBindProgramFragment(con, (RsProgramFragment)ft->loadEnvI32(con, 0, 6));

    if (touch) {
        int newPart = ft->loadEnvI32(con, 2, 0);
        for (int ct2=0; ct2<rate; ct2++) {
@@ -453,6 +457,21 @@ nAllocationUploadToTexture(JNIEnv *_env, jobject _this, jint a, jint mip)
    rsAllocationUploadToTexture((RsAllocation)a, mip);
}

static int
nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jint w, jint h, jint dstFmt, jint srcFmt, jboolean genMips, jintArray data)
{
    RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
    jint len = _env->GetArrayLength(data);
    LOG_API("nAllocationCreateFromBitmap, con(%p), w(%i), h(%i), dstFmt(%i), srcFmt(%i), mip(%i), len(%i)", con, w, h, dstFmt, srcFmt, genMips, len);

    jint *ptr = _env->GetIntArrayElements(data, NULL);
    jint id = (jint)rsAllocationCreateFromBitmap(w, h, (RsElementPredefined)dstFmt, (RsElementPredefined)srcFmt, genMips, ptr);
    _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
    return id;
}



static void
nAllocationDestroy(JNIEnv *_env, jobject _this, jint a)
{
@@ -939,7 +958,7 @@ static JNINativeMethod methods[] = {
{"nAllocationCreateTyped",         "(I)I",                                 (void*)nAllocationCreateTyped },
{"nAllocationCreatePredefSized",   "(II)I",                                (void*)nAllocationCreatePredefSized },
{"nAllocationCreateSized",         "(II)I",                                (void*)nAllocationCreateSized },
//{"nAllocationCreateFromBitmap",    "(I)V",                                 (void*)nAllocationCreateFromBitmap },
{"nAllocationCreateFromBitmap",    "(IIIIZ[I)I",                           (void*)nAllocationCreateFromBitmap },
{"nAllocationUploadToTexture",     "(II)V",                                (void*)nAllocationUploadToTexture },
{"nAllocationDestroy",             "(I)V",                                 (void*)nAllocationDestroy },
{"nAllocationData",                "(I[I)V",                               (void*)nAllocationData_i },
+12 −1
Original line number Diff line number Diff line
@@ -83,12 +83,23 @@ AllocationCreateSized {
	ret RsAllocation
	}

AllocationCreateFromBitmap {
AllocationCreateFromFile {
	param const char *file
	param bool genMips
	ret RsAllocation
	}

AllocationCreateFromBitmap {
	param uint32_t width
	param uint32_t height
	param RsElementPredefined dstFmt
	param RsElementPredefined srcFmt
	param bool genMips
	param const void * data
	ret RsAllocation
	}


AllocationUploadToTexture {
	param RsAllocation alloc
	param uint32_t baseMipLevel
Loading