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

Commit 72226e05 authored by Jason Sams's avatar Jason Sams
Browse files

Implement USAGE_IO_INPUT

Change-Id: Id5b9e3d0a17e4df15eec36d542fde6dc626138b2
parent ec6156f9
Loading
Loading
Loading
Loading
+4 −32
Original line number Diff line number Diff line
@@ -1245,24 +1245,6 @@ public class Allocation extends BaseObj {
        return new Allocation(id, rs, t, usage);
    }

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

        int id = mRS.nAllocationGetSurfaceTextureID(getID(mRS));
        SurfaceTexture st = new SurfaceTexture(id);
        mRS.nAllocationGetSurfaceTextureID2(getID(mRS), st);

        return st;
    }

    /**
     * For allocations used with io operations, returns the handle
     * onto a raw buffer that is being managed by the screen
@@ -1272,7 +1254,10 @@ public class Allocation extends BaseObj {
     *
     */
    public Surface getSurface() {
        return new Surface(getSurfaceTexture());
        if ((mUsage & USAGE_IO_INPUT) == 0) {
            throw new RSInvalidStateException("Allocation is not a surface texture.");
        }
        return mRS.nAllocationGetSurface(getID(mRS));
    }

    /**
@@ -1289,19 +1274,6 @@ public class Allocation extends BaseObj {
        mRS.nAllocationSetSurface(getID(mRS), sur);
    }

    /**
     * @hide
     */
    public void setSurfaceTexture(SurfaceTexture st) {
        mRS.validate();
        if ((mUsage & USAGE_IO_OUTPUT) == 0) {
            throw new RSInvalidStateException("Allocation is not USAGE_IO_OUTPUT.");
        }

        Surface s = new Surface(st);
        mRS.nAllocationSetSurface(getID(mRS), s);
    }

    /**
     * Creates a RenderScript allocation from a bitmap.
     *
+3 −8
Original line number Diff line number Diff line
@@ -303,15 +303,10 @@ public class RenderScript {
        validate();
        rsnAllocationSyncAll(mContext, alloc, src);
    }
    native int rsnAllocationGetSurfaceTextureID(int con, int alloc);
    synchronized int nAllocationGetSurfaceTextureID(int alloc) {
    native Surface rsnAllocationGetSurface(int con, int alloc);
    synchronized Surface nAllocationGetSurface(int alloc) {
        validate();
        return rsnAllocationGetSurfaceTextureID(mContext, alloc);
    }
    native void rsnAllocationGetSurfaceTextureID2(int con, int alloc, SurfaceTexture st);
    synchronized void nAllocationGetSurfaceTextureID2(int alloc, SurfaceTexture st) {
        validate();
        rsnAllocationGetSurfaceTextureID2(mContext, alloc, st);
        return rsnAllocationGetSurface(mContext, alloc);
    }
    native void rsnAllocationSetSurface(int con, int alloc, Surface sur);
    synchronized void nAllocationSetSurface(int alloc, Surface sur) {
+9 −31
Original line number Diff line number Diff line
@@ -236,23 +236,6 @@ nContextSetSurface(JNIEnv *_env, jobject _this, RsContext con, jint width, jint
    rsContextSetSurface(con, width, height, window);
}

static void
nContextSetSurfaceTexture(JNIEnv *_env, jobject _this, RsContext con, jint width, jint height, jobject sur)
{
    LOG_API("nContextSetSurfaceTexture, con(%p), width(%i), height(%i), surface(%p)", con, width, height, (Surface *)sur);

    sp<ANativeWindow> window;
    sp<GLConsumer> st;
    if (sur == 0) {

    } else {
        st = SurfaceTexture_getSurfaceTexture(_env, sur);
        window = new Surface(st->getBufferQueue());
    }

    rsContextSetSurface(con, width, height, window.get());
}

static void
nContextDestroy(JNIEnv *_env, jobject _this, RsContext con)
{
@@ -487,20 +470,17 @@ 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)
static jobject
nAllocationGetSurface(JNIEnv *_env, jobject _this, RsContext con, jint a)
{
    LOG_API("nAllocationGetSurfaceTextureID, con(%p), a(%p)", con, (RsAllocation)a);
    return rsAllocationGetSurfaceTextureID(con, (RsAllocation)a);
}
    LOG_API("nAllocationGetSurface, con(%p), a(%p)", con, (RsAllocation)a);

static void
nAllocationGetSurfaceTextureID2(JNIEnv *_env, jobject _this, RsContext con, jint a, jobject jst)
{
    LOG_API("nAllocationGetSurfaceTextureID2, con(%p), a(%p)", con, (RsAllocation)a);
    sp<GLConsumer> st = SurfaceTexture_getSurfaceTexture(_env, jst);
    IGraphicBufferProducer *v = (IGraphicBufferProducer *)rsAllocationGetSurface(con, (RsAllocation)a);
    sp<IGraphicBufferProducer> bp = v;
    v->decStrong(NULL);

    rsAllocationGetSurfaceTextureID2(con, (RsAllocation)a, st.get(), sizeof(GLConsumer *));
    jobject o = android_view_Surface_createFromIGraphicBufferProducer(_env, bp);
    return o;
}

static void
@@ -1488,7 +1468,6 @@ static JNINativeMethod methods[] = {
{"rsnContextFinish",                 "(I)V",                                  (void*)nContextFinish },
{"rsnContextSetPriority",            "(II)V",                                 (void*)nContextSetPriority },
{"rsnContextSetSurface",             "(IIILandroid/view/Surface;)V",          (void*)nContextSetSurface },
{"rsnContextSetSurfaceTexture",      "(IIILandroid/graphics/SurfaceTexture;)V", (void*)nContextSetSurfaceTexture },
{"rsnContextDestroy",                "(I)V",                                  (void*)nContextDestroy },
{"rsnContextDump",                   "(II)V",                                 (void*)nContextDump },
{"rsnContextPause",                  "(I)V",                                  (void*)nContextPause },
@@ -1526,8 +1505,7 @@ static JNINativeMethod methods[] = {
{"rsnAllocationCopyToBitmap",        "(IILandroid/graphics/Bitmap;)V",        (void*)nAllocationCopyToBitmap },

{"rsnAllocationSyncAll",             "(III)V",                                (void*)nAllocationSyncAll },
{"rsnAllocationGetSurfaceTextureID", "(II)I",                                 (void*)nAllocationGetSurfaceTextureID },
{"rsnAllocationGetSurfaceTextureID2","(IILandroid/graphics/SurfaceTexture;)V",(void*)nAllocationGetSurfaceTextureID2 },
{"rsnAllocationGetSurface",          "(II)Landroid/view/Surface;",            (void*)nAllocationGetSurface },
{"rsnAllocationSetSurface",          "(IILandroid/view/Surface;)V",           (void*)nAllocationSetSurface },
{"rsnAllocationIoSend",              "(II)V",                                 (void*)nAllocationIoSend },
{"rsnAllocationIoReceive",           "(II)V",                                 (void*)nAllocationIoReceive },
+5 −1
Original line number Diff line number Diff line
@@ -97,7 +97,8 @@ public class ImageProcessingActivity extends Activity
        EXPOSURE ("Exposure"),
        WHITE_BALANCE ("White Balance"),
        COLOR_CUBE ("Color Cube"),
        COLOR_CUBE_3D_INTRINSIC ("Color Cube (3D LUT intrinsic)");
        COLOR_CUBE_3D_INTRINSIC ("Color Cube (3D LUT intrinsic)"),
        USAGE_IO ("Usage io)");


        private final String name;
@@ -352,6 +353,9 @@ public class ImageProcessingActivity extends Activity
        case COLOR_CUBE_3D_INTRINSIC:
            mTest = new ColorCube(true);
            break;
        case USAGE_IO:
            mTest = new UsageIO();
            break;
        }

        mTest.createBaseTest(this, mBitmapIn, mBitmapIn2, mBitmapOut);
+66 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2013 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.rs.image;

import java.lang.Math;

import android.view.Surface;
import android.renderscript.Allocation;
import android.renderscript.Element;
import android.renderscript.RenderScript;
import android.renderscript.ScriptIntrinsicConvolve3x3;
import android.renderscript.ScriptIntrinsicColorMatrix;
import android.renderscript.Type;
import android.renderscript.Matrix4f;
import android.renderscript.ScriptGroup;
import android.util.Log;

public class UsageIO extends TestBase {
    private ScriptIntrinsicColorMatrix mMatrix;

    private Allocation mScratchPixelsAllocation1;
    private Allocation mScratchPixelsAllocation2;

    public UsageIO() {
    }

    public void createTest(android.content.res.Resources res) {
        mMatrix = ScriptIntrinsicColorMatrix.create(mRS, Element.U8_4(mRS));

        Matrix4f m = new Matrix4f();
        m.set(1, 0, 0.2f);
        m.set(1, 1, 0.9f);
        m.set(1, 2, 0.2f);
        mMatrix.setColorMatrix(m);

        Type connect = mInPixelsAllocation.getType();

        mScratchPixelsAllocation1 = Allocation.createTyped(mRS, connect, Allocation.USAGE_IO_OUTPUT | Allocation.USAGE_SCRIPT);
        mScratchPixelsAllocation2 = Allocation.createTyped(mRS, connect, Allocation.USAGE_IO_INPUT | Allocation.USAGE_SCRIPT);

        Surface s = mScratchPixelsAllocation2.getSurface();
        mScratchPixelsAllocation1.setSurface(s);
    }

    public void runTest() {
        mScratchPixelsAllocation1.copyFrom(mInPixelsAllocation);
        mScratchPixelsAllocation1.ioSend();
        mScratchPixelsAllocation2.ioReceive();
        mMatrix.forEach(mScratchPixelsAllocation2, mOutPixelsAllocation);
    }

}