Search in sources :

Example 1 with Element

use of android.renderscript.Element in project android_frameworks_base by ParanoidAndroid.

the class ShaderParam method fillInParams.

static ScriptField_ShaderParam_s fillInParams(Element constantElem, HashMap<String, ShaderParam> sourceParams, Transform transform) {
    RenderScriptGL rs = SceneManager.getRS();
    ArrayList<ScriptField_ShaderParam_s.Item> paramList;
    paramList = new ArrayList<ScriptField_ShaderParam_s.Item>();
    int subElemCount = constantElem.getSubElementCount();
    for (int i = 0; i < subElemCount; i++) {
        String inputName = constantElem.getSubElementName(i);
        int offset = constantElem.getSubElementOffsetBytes(i);
        ShaderParam matchingParam = sourceParams.get(inputName);
        Element subElem = constantElem.getSubElement(i);
        // Make one if it's not there
        if (matchingParam == null) {
            if (subElem.getDataType() == Element.DataType.FLOAT_32) {
                matchingParam = new Float4Param(inputName, 0.5f, 0.5f, 0.5f, 0.5f);
            } else if (subElem.getDataType() == Element.DataType.MATRIX_4X4) {
                TransformParam trParam = new TransformParam(inputName);
                trParam.setTransform(transform);
                matchingParam = trParam;
            }
        }
        ScriptField_ShaderParam_s.Item paramRS = new ScriptField_ShaderParam_s.Item();
        paramRS.bufferOffset = offset;
        paramRS.transformTimestamp = 0;
        paramRS.dataTimestamp = 0;
        paramRS.data = matchingParam.getRSData().getAllocation();
        if (subElem.getDataType() == Element.DataType.FLOAT_32) {
            paramRS.float_vecSize = subElem.getVectorSize();
        }
        paramList.add(paramRS);
    }
    ScriptField_ShaderParam_s rsParams = null;
    int paramCount = paramList.size();
    if (paramCount != 0) {
        rsParams = new ScriptField_ShaderParam_s(rs, paramCount);
        for (int i = 0; i < paramCount; i++) {
            rsParams.set(paramList.get(i), i, false);
        }
        rsParams.copyAll();
    }
    return rsParams;
}
Also used : Element(android.renderscript.Element) RenderScriptGL(android.renderscript.RenderScriptGL)

Example 2 with Element

use of android.renderscript.Element in project android_frameworks_base by ParanoidAndroid.

the class Renderable method updateVertexConstants.

void updateVertexConstants(RenderScriptGL rs) {
    Allocation pvParams = null, vertexConstants = null;
    VertexShader pv = mRenderState.mVertex;
    if (pv != null && pv.getObjectConstants() != null) {
        vertexConstants = Allocation.createTyped(rs, pv.getObjectConstants());
        Element vertexConst = vertexConstants.getType().getElement();
        pvParams = ShaderParam.fillInParams(vertexConst, mSourceParams, mTransform).getAllocation();
    }
    mData.pv_const = vertexConstants;
    mData.pv_constParams = pvParams;
}
Also used : Allocation(android.renderscript.Allocation) Element(android.renderscript.Element)

Example 3 with Element

use of android.renderscript.Element in project android_frameworks_base by ParanoidAndroid.

the class Renderable method updateFragmentConstants.

void updateFragmentConstants(RenderScriptGL rs) {
    Allocation pfParams = null, fragmentConstants = null;
    FragmentShader pf = mRenderState.mFragment;
    if (pf != null && pf.getObjectConstants() != null) {
        fragmentConstants = Allocation.createTyped(rs, pf.getObjectConstants());
        Element fragmentConst = fragmentConstants.getType().getElement();
        pfParams = ShaderParam.fillInParams(fragmentConst, mSourceParams, mTransform).getAllocation();
    }
    mData.pf_const = fragmentConstants;
    mData.pf_constParams = pfParams;
}
Also used : Allocation(android.renderscript.Allocation) Element(android.renderscript.Element)

Example 4 with Element

use of android.renderscript.Element in project platform_frameworks_base by android.

the class Camera2Source method onOpen.

@Override
protected void onOpen() {
    mLooperThread = new CameraTestThread();
    Handler mHandler;
    try {
        mHandler = mLooperThread.start();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        throw new RuntimeException(e);
    }
    try {
        String backCameraId = "0";
        BlockingCameraManager blkManager = new BlockingCameraManager(mCameraManager);
        mCamera = blkManager.openCamera(backCameraId, /*listener*/
        null, mHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    } catch (BlockingOpenException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
    Element ele = Element.createPixel(mRS, Element.DataType.UNSIGNED_8, Element.DataKind.PIXEL_YUV);
    rgbConverter = ScriptIntrinsicYuvToRGB.create(mRS, ele);
    Type.Builder yuvBuilder = new Type.Builder(mRS, ele);
    yuvBuilder.setYuvFormat(ImageFormat.YUV_420_888);
    yuvBuilder.setX(mWidth);
    yuvBuilder.setY(mHeight);
    mAllocationIn = Allocation.createTyped(mRS, yuvBuilder.create(), Allocation.USAGE_SCRIPT | Allocation.USAGE_IO_INPUT);
    mSurface = mAllocationIn.getSurface();
    mAllocationIn.setOnBufferAvailableListener(this);
    rgbConverter.setInput(mAllocationIn);
    mBitmap = Bitmap.createBitmap(mWidth, mHeight, Bitmap.Config.ARGB_8888);
    mAllocationOut = Allocation.createFromBitmap(mRS, mBitmap);
    Log.v(TAG, "mcamera: " + mCamera);
    List<Surface> surfaces = new ArrayList<Surface>();
    surfaces.add(mSurface);
    CaptureRequest.Builder mCaptureRequest = null;
    try {
        BlockingSessionCallback blkSession = new BlockingSessionCallback();
        mCamera.createCaptureSession(surfaces, blkSession, mHandler);
        mCaptureRequest = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
        mCaptureRequest.addTarget(mSurface);
        mCameraSession = blkSession.waitAndGetSession(SESSION_TIMEOUT_MS);
    } catch (CameraAccessException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
    try {
        mCameraSession.setRepeatingRequest(mCaptureRequest.build(), new MyCaptureCallback(), mHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
    mProperties = null;
    try {
        mProperties = mCameraManager.getCameraCharacteristics(mCamera.getId());
    } catch (CameraAccessException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
Also used : BlockingSessionCallback(com.android.ex.camera2.blocking.BlockingSessionCallback) Element(android.renderscript.Element) ArrayList(java.util.ArrayList) Handler(android.os.Handler) BlockingCameraManager(com.android.ex.camera2.blocking.BlockingCameraManager) BlockingOpenException(com.android.ex.camera2.blocking.BlockingCameraManager.BlockingOpenException) CameraAccessException(android.hardware.camera2.CameraAccessException) Surface(android.view.Surface) CameraAccessException(android.hardware.camera2.CameraAccessException) Type(android.renderscript.Type) FrameType(androidx.media.filterfw.FrameType) BlockingOpenException(com.android.ex.camera2.blocking.BlockingCameraManager.BlockingOpenException) CaptureRequest(android.hardware.camera2.CaptureRequest)

Example 5 with Element

use of android.renderscript.Element in project android_frameworks_base by DirtyUnicorns.

the class Camera2Source method onOpen.

@Override
protected void onOpen() {
    mLooperThread = new CameraTestThread();
    Handler mHandler;
    try {
        mHandler = mLooperThread.start();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        throw new RuntimeException(e);
    }
    try {
        String backCameraId = "0";
        BlockingCameraManager blkManager = new BlockingCameraManager(mCameraManager);
        mCamera = blkManager.openCamera(backCameraId, /*listener*/
        null, mHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    } catch (BlockingOpenException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
    Element ele = Element.createPixel(mRS, Element.DataType.UNSIGNED_8, Element.DataKind.PIXEL_YUV);
    rgbConverter = ScriptIntrinsicYuvToRGB.create(mRS, ele);
    Type.Builder yuvBuilder = new Type.Builder(mRS, ele);
    yuvBuilder.setYuvFormat(ImageFormat.YUV_420_888);
    yuvBuilder.setX(mWidth);
    yuvBuilder.setY(mHeight);
    mAllocationIn = Allocation.createTyped(mRS, yuvBuilder.create(), Allocation.USAGE_SCRIPT | Allocation.USAGE_IO_INPUT);
    mSurface = mAllocationIn.getSurface();
    mAllocationIn.setOnBufferAvailableListener(this);
    rgbConverter.setInput(mAllocationIn);
    mBitmap = Bitmap.createBitmap(mWidth, mHeight, Bitmap.Config.ARGB_8888);
    mAllocationOut = Allocation.createFromBitmap(mRS, mBitmap);
    Log.v(TAG, "mcamera: " + mCamera);
    List<Surface> surfaces = new ArrayList<Surface>();
    surfaces.add(mSurface);
    CaptureRequest.Builder mCaptureRequest = null;
    try {
        BlockingSessionCallback blkSession = new BlockingSessionCallback();
        mCamera.createCaptureSession(surfaces, blkSession, mHandler);
        mCaptureRequest = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
        mCaptureRequest.addTarget(mSurface);
        mCameraSession = blkSession.waitAndGetSession(SESSION_TIMEOUT_MS);
    } catch (CameraAccessException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
    try {
        mCameraSession.setRepeatingRequest(mCaptureRequest.build(), new MyCaptureCallback(), mHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
    mProperties = null;
    try {
        mProperties = mCameraManager.getCameraCharacteristics(mCamera.getId());
    } catch (CameraAccessException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
Also used : BlockingSessionCallback(com.android.ex.camera2.blocking.BlockingSessionCallback) Element(android.renderscript.Element) ArrayList(java.util.ArrayList) Handler(android.os.Handler) BlockingCameraManager(com.android.ex.camera2.blocking.BlockingCameraManager) BlockingOpenException(com.android.ex.camera2.blocking.BlockingCameraManager.BlockingOpenException) CameraAccessException(android.hardware.camera2.CameraAccessException) Surface(android.view.Surface) CameraAccessException(android.hardware.camera2.CameraAccessException) Type(android.renderscript.Type) FrameType(androidx.media.filterfw.FrameType) BlockingOpenException(com.android.ex.camera2.blocking.BlockingCameraManager.BlockingOpenException) CaptureRequest(android.hardware.camera2.CaptureRequest)

Aggregations

Element (android.renderscript.Element)7 CameraAccessException (android.hardware.camera2.CameraAccessException)4 CaptureRequest (android.hardware.camera2.CaptureRequest)4 Handler (android.os.Handler)4 Type (android.renderscript.Type)4 Surface (android.view.Surface)4 FrameType (androidx.media.filterfw.FrameType)4 BlockingCameraManager (com.android.ex.camera2.blocking.BlockingCameraManager)4 BlockingOpenException (com.android.ex.camera2.blocking.BlockingCameraManager.BlockingOpenException)4 BlockingSessionCallback (com.android.ex.camera2.blocking.BlockingSessionCallback)4 ArrayList (java.util.ArrayList)4 Allocation (android.renderscript.Allocation)2 RenderScriptGL (android.renderscript.RenderScriptGL)1