Java Code Examples for android.graphics.SurfaceTexture#updateTexImage()

The following examples show how to use android.graphics.SurfaceTexture#updateTexImage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SurfaceTexturePlatformWrapper.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@CalledByNative
private static void updateTexImage(SurfaceTexture surfaceTexture) {
    try {
        surfaceTexture.updateTexImage();
    } catch (RuntimeException e) {
        Log.e(TAG, "Error calling updateTexImage", e);
    }
}
 
Example 2
Source File: ColorFade.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private boolean captureScreenshotTextureAndSetViewport() {
    if (!attachEglContext()) {
        return false;
    }
    try {
        if (!mTexNamesGenerated) {
            GLES20.glGenTextures(1, mTexNames, 0);
            if (checkGlErrors("glGenTextures")) {
                return false;
            }
            mTexNamesGenerated = true;
        }

        final SurfaceTexture st = new SurfaceTexture(mTexNames[0]);
        final Surface s = new Surface(st);
        try {
            SurfaceControl.screenshot(SurfaceControl.getBuiltInDisplay(
                    SurfaceControl.BUILT_IN_DISPLAY_ID_MAIN), s);
            st.updateTexImage();
            st.getTransformMatrix(mTexMatrix);
        } finally {
            s.release();
            st.release();
        }

        // Set up texture coordinates for a quad.
        // We might need to change this if the texture ends up being
        // a different size from the display for some reason.
        mTexCoordBuffer.put(0, 0f); mTexCoordBuffer.put(1, 0f);
        mTexCoordBuffer.put(2, 0f); mTexCoordBuffer.put(3, 1f);
        mTexCoordBuffer.put(4, 1f); mTexCoordBuffer.put(5, 1f);
        mTexCoordBuffer.put(6, 1f); mTexCoordBuffer.put(7, 0f);

        // Set up our viewport.
        GLES20.glViewport(0, 0, mDisplayWidth, mDisplayHeight);
        ortho(0, mDisplayWidth, 0, mDisplayHeight, -1, 1);
    } finally {
        detachEglContext();
    }
    return true;
}
 
Example 3
Source File: TextureRect.java    From GLEXP-Team-onebillion with Apache License 2.0 4 votes vote down vote up
public void drawSurface(OBRenderer renderer, float l, float t, float r, float b, SurfaceTexture surfaceTexture,boolean mirrored)
{
    fillOutRectVertexData(vertices,l,t,r,b,POSITION_COMPONENT_COUNT + UV_COMPONENT_COUNT);

    float m[] = new float[16];
    surfaceTexture.getTransformMatrix(m);
    if (!isIdentity(m) && !mirrored)
    {
        float v[] = new float[4];
        v[0] = uvLeft;v[1] = uvBottom;v[2] = 0;v[3] = 1;
        float o[] = new float[4];
        android.opengl.Matrix.multiplyMV(o,0,m,0,v,0);
        v[0] = uvRight;v[1] = uvTop;v[2] = 0;v[3] = 1;
        uvLeft = o[0];uvTop = o[1];
        android.opengl.Matrix.multiplyMV(o,0,m,0,v,0);
        uvRight = o[0];
        uvBottom = o[1];
    }

    fillOutRectTextureData(vertices,uvLeft,uvTop,uvRight,uvBottom,POSITION_COMPONENT_COUNT + UV_COMPONENT_COUNT);
    if (vertexArray == null)
        vertexArray = new VertexArray(vertices);
    else
        vertexArray.put(vertices);

    bindSurfaceData((SurfaceShaderProgram) renderer.surfaceProgram);

    try
    {
        surfaceTexture.updateTexImage();
    }catch (Exception e)
    {
        e.printStackTrace();
    }

    glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,renderer.textureObjectId(2));
    GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
    GLES20.glEnable(GLES20.GL_BLEND);

    glDrawArrays(GL_TRIANGLE_STRIP,0,4);

    GLES20.glFinish();
}
 
Example 4
Source File: VideoSurfaceProcessor.java    From AAVT with Apache License 2.0 4 votes vote down vote up
private void glRun(){
    EglHelper egl=new EglHelper();
    boolean ret=egl.createGLESWithSurface(new EGLConfigAttrs(),new EGLContextAttrs(),new SurfaceTexture(1));
    if(!ret){
        //todo 错误处理
        return;
    }
    int mInputSurfaceTextureId = GpuUtils.createTextureID(true);
    SurfaceTexture mInputSurfaceTexture = new SurfaceTexture(mInputSurfaceTextureId);

    Point size=mProvider.open(mInputSurfaceTexture);
    AvLog.d(TAG,"Provider Opened . data size (x,y)="+size.x+"/"+size.y);
    if(size.x<=0||size.y<=0){
        //todo 错误处理
        destroyGL(egl);
        synchronized (LOCK){
            LOCK.notifyAll();
        }
        return;
    }
    int mSourceWidth = size.x;
    int mSourceHeight = size.y;
    synchronized (LOCK){
        LOCK.notifyAll();
    }
    //要求数据源提供者必须同步返回数据大小
    if(mSourceWidth <=0|| mSourceHeight <=0){
        error(1,"video source return inaccurate size to SurfaceTextureActuator");
        return;
    }

    if(mRenderer==null){
        mRenderer=new WrapRenderer(null);
    }
    FrameBuffer sourceFrame=new FrameBuffer();
    mRenderer.create();
    mRenderer.sizeChanged(mSourceWidth, mSourceHeight);
    mRenderer.setFlag(mProvider.isLandscape()?WrapRenderer.TYPE_CAMERA:WrapRenderer.TYPE_MOVE);

    //用于其他的回调
    RenderBean rb=new RenderBean();
    rb.egl=egl;
    rb.sourceWidth= mSourceWidth;
    rb.sourceHeight= mSourceHeight;
    rb.endFlag=false;
    rb.threadId=Thread.currentThread().getId();
    AvLog.d(TAG,"Processor While Loop Entry");
    //要求数据源必须同步填充SurfaceTexture,填充完成前等待
    while (!mProvider.frame()&&mGLThreadFlag){
        mInputSurfaceTexture.updateTexImage();
        mInputSurfaceTexture.getTransformMatrix(mRenderer.getTextureMatrix());
        AvLog.d(TAG,"timestamp:"+ mInputSurfaceTexture.getTimestamp());
        sourceFrame.bindFrameBuffer(mSourceWidth, mSourceHeight);
        GLES20.glViewport(0,0, mSourceWidth, mSourceHeight);
        mRenderer.draw(mInputSurfaceTextureId);
        sourceFrame.unBindFrameBuffer();
        rb.textureId=sourceFrame.getCacheTextureId();
        //接收数据源传入的时间戳
        rb.timeStamp=mProvider.getTimeStamp();
        rb.textureTime= mInputSurfaceTexture.getTimestamp();
        observable.notify(rb);
    }
    AvLog.d(TAG,"out of gl thread loop");
    synchronized (LOCK){
        rb.endFlag=true;
        observable.notify(rb);
        mRenderer.destroy();
        destroyGL(egl);
        LOCK.notifyAll();
        AvLog.d(TAG,"gl thread exit");
    }
}
 
Example 5
Source File: SurfaceTexturePlatformWrapper.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@CalledByNative
private static void updateTexImage(SurfaceTexture surfaceTexture) {
    surfaceTexture.updateTexImage();
}
 
Example 6
Source File: SurfaceTexturePlatformWrapper.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@CalledByNative
private static void updateTexImage(SurfaceTexture surfaceTexture) {
    surfaceTexture.updateTexImage();
}