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

Commit 532efd3c authored by Jason Sams's avatar Jason Sams
Browse files

Start implementing SurfaceTexture streaming into RS allocations.

Change-Id: I561fbb63c63371ea59047c07fb2d68c21d16e76b

Conflicts:

	libs/rs/rsAllocation.h
parent d51280f1
Loading
Loading
Loading
Loading
+63 −1
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.content.res.Resources;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.SurfaceTexture;
import android.util.Log;
import android.util.TypedValue;

@@ -78,6 +79,8 @@ public class Allocation extends BaseObj {
    boolean mConstrainedFace;
    boolean mConstrainedY;
    boolean mConstrainedZ;
    boolean mReadAllowed = true;
    boolean mWriteAllowed = true;
    int mSelectedY;
    int mSelectedZ;
    int mSelectedLOD;
@@ -127,6 +130,32 @@ public class Allocation extends BaseObj {
     */
    public static final int USAGE_GRAPHICS_RENDER_TARGET = 0x0010;

    /**
     * USAGE_GRAPHICS_SURFACE_TEXTURE_INPUT The allcation will be
     * used with a SurfaceTexture object.  This usage will cause the
     * allocation to be created read only.
     *
     * @hide
     */
    public static final int USAGE_GRAPHICS_SURFACE_TEXTURE_INPUT_OPAQUE = 0x0020;

    /**
     * USAGE_GRAPHICS_SURFACE_TEXTURE_INPUT The allcation will be
     * used with a SurfaceTexture object.  This usage will cause the
     * allocation to be created read only.
     *
     * @hide
     */

    public static final int USAGE_IO_INPUT = 0x0040;
    /**
     * USAGE_GRAPHICS_SURFACE_TEXTURE_INPUT The allcation will be
     * used with a SurfaceTexture object.  This usage will cause the
     * allocation to be created read only.
     *
     * @hide
     */
    public static final int USAGE_IO_OUTPUT = 0x0080;

    /**
     * Controls mipmap behavior when using the bitmap creation and
@@ -187,10 +216,26 @@ public class Allocation extends BaseObj {
                       USAGE_GRAPHICS_TEXTURE |
                       USAGE_GRAPHICS_VERTEX |
                       USAGE_GRAPHICS_CONSTANTS |
                       USAGE_GRAPHICS_RENDER_TARGET)) != 0) {
                       USAGE_GRAPHICS_RENDER_TARGET |
                       USAGE_GRAPHICS_SURFACE_TEXTURE_INPUT_OPAQUE |
                       USAGE_IO_INPUT |
                       USAGE_IO_OUTPUT)) != 0) {
            throw new RSIllegalArgumentException("Unknown usage specified.");
        }

        if ((usage & (USAGE_GRAPHICS_SURFACE_TEXTURE_INPUT_OPAQUE | USAGE_IO_INPUT)) != 0) {
            mWriteAllowed = false;

            if ((usage & ~(USAGE_GRAPHICS_SURFACE_TEXTURE_INPUT_OPAQUE |
                           USAGE_IO_INPUT |
                           USAGE_GRAPHICS_TEXTURE |
                           USAGE_SCRIPT)) != 0) {
                throw new RSIllegalArgumentException("Invalid usage combination.");
            }
        }

        mType = t;
        mUsage = usage;

        if (t != null) {
            updateCacheInfo(t);
@@ -1005,6 +1050,23 @@ public class Allocation extends BaseObj {
        return new Allocation(id, rs, t, usage);
    }

    /**
     *
     *
     * @hide
     *
     */
    public SurfaceTexture getSurfaceTexture() {
        if ((mUsage & USAGE_GRAPHICS_SURFACE_TEXTURE_INPUT_OPAQUE) == 0) {
            throw new RSInvalidStateException("Allocation is not a surface texture.");
        }

        int id = mRS.nAllocationGetSurfaceTextureID(getID());
        return new SurfaceTexture(id);

    }


    /**
     * Creates a non-mipmapped renderscript allocation to use as a
     * graphics texture
+6 −0
Original line number Diff line number Diff line
@@ -269,6 +269,12 @@ public class RenderScript {
        validate();
        rsnAllocationSyncAll(mContext, alloc, src);
    }
    native int rsnAllocationGetSurfaceTextureID(int con, int alloc);
    synchronized int nAllocationGetSurfaceTextureID(int alloc) {
        validate();
        return rsnAllocationGetSurfaceTextureID(mContext, alloc);
    }

    native void rsnAllocationGenerateMipmaps(int con, int alloc);
    synchronized void nAllocationGenerateMipmaps(int alloc) {
        validate();
+8 −0
Original line number Diff line number Diff line
@@ -443,6 +443,13 @@ nAllocationSyncAll(JNIEnv *_env, jobject _this, RsContext con, jint a, jint bits
    rsAllocationSyncAll(con, (RsAllocation)a, (RsAllocationUsageType)bits);
}

static jint
nAllocationGetSurfaceTextureID(JNIEnv *_env, jobject _this, RsContext con, jint a)
{
    LOG_API("nAllocationGetSurfaceTextureID, con(%p), a(%p)", con, (RsAllocation)a);
    return rsAllocationGetSurfaceTextureID(con, (RsAllocation)a);
}

static void
nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, RsContext con, jint alloc)
{
@@ -1258,6 +1265,7 @@ static JNINativeMethod methods[] = {
{"rsnAllocationCopyToBitmap",        "(IILandroid/graphics/Bitmap;)V",        (void*)nAllocationCopyToBitmap },

{"rsnAllocationSyncAll",             "(III)V",                                (void*)nAllocationSyncAll },
{"rsnAllocationGetSurfaceTextureID", "(II)I",                                 (void*)nAllocationGetSurfaceTextureID },
{"rsnAllocationData1D",              "(IIIII[II)V",                           (void*)nAllocationData1D_i },
{"rsnAllocationData1D",              "(IIIII[SI)V",                           (void*)nAllocationData1D_s },
{"rsnAllocationData1D",              "(IIIII[BI)V",                           (void*)nAllocationData1D_b },
+4 −1
Original line number Diff line number Diff line
@@ -99,8 +99,11 @@ enum RsAllocationUsageType {
    RS_ALLOCATION_USAGE_GRAPHICS_VERTEX = 0x0004,
    RS_ALLOCATION_USAGE_GRAPHICS_CONSTANTS = 0x0008,
    RS_ALLOCATION_USAGE_GRAPHICS_RENDER_TARGET = 0x0010,
    RS_ALLOCATION_USAGE_GRAPHICS_SURFACE_TEXTURE_INPUT_OPAQUE = 0x0020,
    RS_ALLOCATION_USAGE_IO_INPUT = 0x0040,
    RS_ALLOCATION_USAGE_IO_OUTPUT = 0x0080,

    RS_ALLOCATION_USAGE_ALL = 0x000F
    RS_ALLOCATION_USAGE_ALL = 0x00FF
};

enum RsAllocationMipmapControl {
+13 −0
Original line number Diff line number Diff line
@@ -134,6 +134,13 @@ static void Upload2DTexture(const Context *rsc, const Allocation *alloc, bool is
static void UploadToTexture(const Context *rsc, const Allocation *alloc) {
    DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;

    if (alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_GRAPHICS_SURFACE_TEXTURE_INPUT_OPAQUE) {
        if (!drv->textureID) {
            RSD_CALL_GL(glGenTextures, 1, &drv->textureID);
        }
        return;
    }

    if (!drv->glType || !drv->glFormat) {
        return;
    }
@@ -370,6 +377,12 @@ void rsdAllocationMarkDirty(const Context *rsc, const Allocation *alloc) {
    drv->uploadDeferred = true;
}

int32_t rsdAllocationInitSurfaceTexture(const Context *rsc, const Allocation *alloc) {
    DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
    UploadToTexture(rsc, alloc);
    return drv->textureID;
}

void rsdAllocationData1D(const Context *rsc, const Allocation *alloc,
                         uint32_t xoff, uint32_t lod, uint32_t count,
                         const void *data, uint32_t sizeBytes) {
Loading