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

Commit 5edc608a authored by Jason Sams's avatar Jason Sams
Browse files

Implement allocation resizing.

Change-Id: Ie38d42419d595cec730a8721cc1321c5edb6b4d6
parent 2a2a38db
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -182,6 +182,24 @@ public class Allocation extends BaseObj {
        mRS.nAllocationRead(mID, d);
    }

    public void resize(int dimX) {
        if ((mType.getY() > 0)|| (mType.getZ() > 0) || mType.getFaces() || mType.getLOD()) {
            throw new IllegalStateException("Resize only support for 1D allocations at this time.");
        }
        mRS.nAllocationResize1D(mID, dimX);
    }

    /*
    public void resize(int dimX, int dimY) {
        if ((mType.getZ() > 0) || mType.getFaces() || mType.getLOD()) {
            throw new IllegalStateException("Resize only support for 2D allocations at this time.");
        }
        if (mType.getY() == 0) {
            throw new IllegalStateException("Resize only support for 2D allocations at this time.");
        }
        mRS.nAllocationResize2D(mID, dimX, dimY);
    }
    */

    public class Adapter1D extends BaseObj {
        Adapter1D(int id, RenderScript rs) {
+9 −0
Original line number Diff line number Diff line
@@ -254,6 +254,15 @@ public class RenderScript {
        return rsnAllocationGetType(mContext, id);
    }

    native void rsnAllocationResize1D(int con, int id, int dimX);
    synchronized void nAllocationResize1D(int id, int dimX) {
        rsnAllocationResize1D(mContext, id, dimX);
    }
    native void rsnAllocationResize2D(int con, int id, int dimX, int dimY);
    synchronized void nAllocationResize2D(int id, int dimX, int dimY) {
        rsnAllocationResize2D(mContext, id, dimX, dimY);
    }

    native int  rsnFileA3DCreateFromAssetStream(int con, int assetStream);
    synchronized int nFileA3DCreateFromAssetStream(int assetStream) {
        return rsnFileA3DCreateFromAssetStream(mContext, assetStream);
+16 −0
Original line number Diff line number Diff line
@@ -587,6 +587,20 @@ nAllocationGetType(JNIEnv *_env, jobject _this, RsContext con, jint a)
    return (jint) rsAllocationGetType(con, (RsAllocation)a);
}

static void
nAllocationResize1D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint dimX)
{
    LOG_API("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", con, (RsAllocation)alloc, dimX);
    rsAllocationResize1D(con, (RsAllocation)alloc, dimX);
}

static void
nAllocationResize2D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint dimX, jint dimY)
{
    LOG_API("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i), sizeY(%i)", con, (RsAllocation)alloc, dimX, dimY);
    rsAllocationResize2D(con, (RsAllocation)alloc, dimX, dimY);
}

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

static int
@@ -1252,6 +1266,8 @@ static JNINativeMethod methods[] = {
{"rsnAllocationRead",                "(II[I)V",                               (void*)nAllocationRead_i },
{"rsnAllocationRead",                "(II[F)V",                               (void*)nAllocationRead_f },
{"rsnAllocationGetType",             "(II)I",                                 (void*)nAllocationGetType},
{"rsnAllocationResize1D",            "(III)V",                                (void*)nAllocationResize1D },
{"rsnAllocationResize2D",            "(IIII)V",                               (void*)nAllocationResize2D },

{"rsnAdapter1DBindAllocation",       "(III)V",                                (void*)nAdapter1DBindAllocation },
{"rsnAdapter1DSetConstraint",        "(IIII)V",                               (void*)nAdapter1DSetConstraint },
+11 −0
Original line number Diff line number Diff line
@@ -280,6 +280,17 @@ AllocationGetType {
	ret const void*
	}

AllocationResize1D {
	param RsAllocation va
	param uint32_t dimX
	}

AllocationResize2D {
	param RsAllocation va
	param uint32_t dimX
	param uint32_t dimY
	}

SamplerBegin {
	}

+47 −2
Original line number Diff line number Diff line
@@ -488,12 +488,13 @@ void Allocation::sendDirty() const
    }
}

void Allocation::incRefs(const void *ptr, size_t ct) const
void Allocation::incRefs(const void *ptr, size_t ct, size_t startOff) const
{
    const uint8_t *p = static_cast<const uint8_t *>(ptr);
    const Element *e = mType->getElement();
    uint32_t stride = e->getSizeBytes();

    p += stride * startOff;
    while (ct > 0) {
        e->incRefs(p);
        ct --;
@@ -501,12 +502,13 @@ void Allocation::incRefs(const void *ptr, size_t ct) const
    }
}

void Allocation::decRefs(const void *ptr, size_t ct) const
void Allocation::decRefs(const void *ptr, size_t ct, size_t startOff) const
{
    const uint8_t *p = static_cast<const uint8_t *>(ptr);
    const Element *e = mType->getElement();
    uint32_t stride = e->getSizeBytes();

    p += stride * startOff;
    while (ct > 0) {
        e->decRefs(p);
        ct --;
@@ -514,6 +516,37 @@ void Allocation::decRefs(const void *ptr, size_t ct) const
    }
}

void Allocation::copyRange1D(Context *rsc, const Allocation *src, int32_t srcOff, int32_t destOff, int32_t len)
{
}

void Allocation::resize1D(Context *rsc, uint32_t dimX)
{
    Type *t = mType->cloneAndResize1D(rsc, dimX);

    uint32_t oldDimX = mType->getDimX();
    if (dimX == oldDimX) {
        return;
    }

    if (dimX < oldDimX) {
        decRefs(mPtr, oldDimX - dimX, dimX);
    }
    mPtr = realloc(mPtr, t->getSizeBytes());

    if (dimX > oldDimX) {
        const Element *e = mType->getElement();
        uint32_t stride = e->getSizeBytes();
        memset(((uint8_t *)mPtr) + stride * oldDimX, 0, stride * (dimX - oldDimX));
    }
    mType.set(t);
}

void Allocation::resize2D(Context *rsc, uint32_t dimX, uint32_t dimY)
{
    LOGE("not implemented");
}

/////////////////
//

@@ -822,6 +855,18 @@ void rsi_AllocationRead(Context *rsc, RsAllocation va, void *data)
    a->read(data);
}

void rsi_AllocationResize1D(Context *rsc, RsAllocation va, uint32_t dimX)
{
    Allocation *a = static_cast<Allocation *>(va);
    a->resize1D(rsc, dimX);
}

void rsi_AllocationResize2D(Context *rsc, RsAllocation va, uint32_t dimX, uint32_t dimY)
{
    Allocation *a = static_cast<Allocation *>(va);
    a->resize2D(rsc, dimX, dimY);
}

const void* rsi_AllocationGetType(Context *rsc, RsAllocation va)
{
    Allocation *a = static_cast<Allocation *>(va);
Loading