SurfaceViewRenderer
SurfaceEglRenderer / EglRenderer
app
-1-> SurfaceViewRenderer
-1-2-> SurfaceEglRenderer(EglRenderer)
-1-2-3-> VideoFrameDrawer
-1-> SurfaceViewRenderer.init
-1-2-> GlRectDrawer(GlGenericDrawer,
-1-2-> SurfaceEglRenderer.init
-1-2-3-> render thread
render thread:
eglBase = EglBase.create(sharedContext, configAttributes); // EGl context
-1-> EglBase14Impl
-1-2-> EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY);
-1-2-> EGL14.eglChooseConfig
-1-2-> EGL14.eglCreateContext
// UI线程
// SurfaceHolder.Callback interface. surfaceCreated
postToRenderThread(eglSurfaceCreationRunnable);
render thread:
-1-> eglBase.createSurface((SurfaceTexture) surface); // Create EGLSurface from the Android SurfaceTexture.
-1-2> EglBase14Impl.createSurfaceInternal
-1-2-3-> EGL14.eglCreateWindowSurface
-1-> eglBase.makeCurrent();
-1-> GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 1);
// View layout interface.
-1-> SurfaceViewRenderer.onMeasure
-1-2-> setMeasuredDimension
// View layout interface.
-1-> SurfaceViewRenderer.onLayout
-1-2-> eglRenderer.setLayoutAspectRatio
-1-2-> getHolder().setFixedSize
// VideoSink interface.
-1-> EglRenderer.onFrame
-1-2-> pendingFrame.retain();
-1-2-> renderThreadHandler.post(this ::renderFrameOnRenderThread);
-1-2-3-> renderFrameOnRenderThread
-1-2-3-4-> VideoFrameDrawer.drawFrame
-1-2-3-4-5> VideoFrameDrawer.drawTexture
-1-2-3-4-5-6-> VideoFrameDrawer.convertMatrixFromAndroidGraphicsMatrix
-1-2-3-4-5-6-7-> drawOes
-1-2-3-4-5-6-7-8-> GlGenericDrawer.prepareShader
-1-2-3-4-5-6-7-8-9-> GlShader
-1-2-3-4-5-6-7-8-> GLES20.glUniform1i(shader.getUniformLocation("y_tex"), 0);
-1-2-3-4-5-6-7-8-> GLES20.glUniform1i(shader.getUniformLocation("u_tex"), 1);
-1-2-3-4-5-6-7-8-> GLES20.glUniform1i(shader.getUniformLocation("v_tex"), 2);
-1-2-3-4-5-6-7-8-> texMatrixLocation = shader.getUniformLocation(TEXTURE_MATRIX_NAME);
-1-2-3-4-5-6-7-8-> inPosLocation = shader.getAttribLocation(INPUT_VERTEX_COORDINATE_NAME);
-1-2-3-4-5-6-7-8-> inTcLocation = shader.getAttribLocation(INPUT_TEXTURE_COORDINATE_NAME);
// Bind the texture.
-1-2-3-4-5-6-7-8->GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
-1-2-3-4-5-6-7-8->GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, oesTextureId);
// Draw the texture.
-1-2-3-4-5-6-7-8->GLES20.glViewport(viewportX, viewportY, viewportWidth, viewportHeight);
-1-2-3-4-5-6-7-8->GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
// Unbind the texture as a precaution.
-1-2-3-4-5-6-7-8->GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, 0);
-1-2-3-> frame.release(); //renderFrameOnRenderThread
-1-2-3-> eglBase.swapBuffers
app
-1-> SurfaceViewRenderer.release
//render thread:
-1-2-> EglRenderer.release
-1-2-3> GLES20.glUseProgram(/* program= */ 0);
-1-2-3> GlGenericDrawer.release
-1-2-3> VideoFrameDrawer.release
-1-2-3> eglBase.detachCurrent();
-1-2-3> eglBase.release();
//render thread exit