Android GlDrawer: Add frame size as argument to draw functions

BUG=b/28544933

Review-Url: https://codereview.webrtc.org/1948473002
Cr-Commit-Position: refs/heads/master@{#12623}
This commit is contained in:
magjed
2016-05-04 02:02:11 -07:00
committed by Commit bot
parent c6c00b32da
commit 71af75dc3c
7 changed files with 36 additions and 21 deletions

View File

@ -119,13 +119,14 @@ public class GlRectDrawer implements RendererCommon.GlDrawer {
* allocated at the first call to this function.
*/
@Override
public void drawOes(int oesTextureId, float[] texMatrix, int x, int y, int width, int height) {
public void drawOes(int oesTextureId, float[] texMatrix, int frameWidth, int frameHeight,
int viewportX, int viewportY, int viewportWidth, int viewportHeight) {
prepareShader(OES_FRAGMENT_SHADER_STRING, texMatrix);
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
// updateTexImage() may be called from another thread in another EGL context, so we need to
// bind/unbind the texture in each draw call so that GLES understads it's a new texture.
GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, oesTextureId);
drawRectangle(x, y, width, height);
drawRectangle(viewportX, viewportY, viewportWidth, viewportHeight);
GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, 0);
}
@ -134,11 +135,12 @@ public class GlRectDrawer implements RendererCommon.GlDrawer {
* are allocated at the first call to this function.
*/
@Override
public void drawRgb(int textureId, float[] texMatrix, int x, int y, int width, int height) {
public void drawRgb(int textureId, float[] texMatrix, int frameWidth, int frameHeight,
int viewportX, int viewportY, int viewportWidth, int viewportHeight) {
prepareShader(RGB_FRAGMENT_SHADER_STRING, texMatrix);
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId);
drawRectangle(x, y, width, height);
drawRectangle(viewportX, viewportY, viewportWidth, viewportHeight);
// Unbind the texture as a precaution.
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
}
@ -148,14 +150,15 @@ public class GlRectDrawer implements RendererCommon.GlDrawer {
* allocated at the first call to this function.
*/
@Override
public void drawYuv(int[] yuvTextures, float[] texMatrix, int x, int y, int width, int height) {
public void drawYuv(int[] yuvTextures, float[] texMatrix, int frameWidth, int frameHeight,
int viewportX, int viewportY, int viewportWidth, int viewportHeight) {
prepareShader(YUV_FRAGMENT_SHADER_STRING, texMatrix);
// Bind the textures.
for (int i = 0; i < 3; ++i) {
GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + i);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, yuvTextures[i]);
}
drawRectangle(x, y, width, height);
drawRectangle(viewportX, viewportY, viewportWidth, viewportHeight);
// Unbind the textures as a precaution..
for (int i = 0; i < 3; ++i) {
GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + i);

View File

@ -40,9 +40,12 @@ public class RendererCommon {
* implied by the current EGL context of the calling thread and requires no explicit argument.
* The coordinates specify the viewport location on the surface target.
*/
void drawOes(int oesTextureId, float[] texMatrix, int x, int y, int width, int height);
void drawRgb(int textureId, float[] texMatrix, int x, int y, int width, int height);
void drawYuv(int[] yuvTextures, float[] texMatrix, int x, int y, int width, int height);
void drawOes(int oesTextureId, float[] texMatrix, int frameWidth, int frameHeight,
int viewportX, int viewportY, int viewportWidth, int viewportHeight);
void drawRgb(int textureId, float[] texMatrix, int frameWidth, int frameHeight,
int viewportX, int viewportY, int viewportWidth, int viewportHeight);
void drawYuv(int[] yuvTextures, float[] texMatrix, int frameWidth, int frameHeight,
int viewportX, int viewportY, int viewportWidth, int viewportHeight);
/**
* Release all GL resources. This needs to be done manually, otherwise resources may leak.

View File

@ -489,9 +489,11 @@ public class SurfaceViewRenderer extends SurfaceView
}
yuvUploader.uploadYuvData(
yuvTextures, frame.width, frame.height, frame.yuvStrides, frame.yuvPlanes);
drawer.drawYuv(yuvTextures, texMatrix, 0, 0, surfaceSize.x, surfaceSize.y);
drawer.drawYuv(yuvTextures, texMatrix, frame.rotatedWidth(), frame.rotatedHeight(),
0, 0, surfaceSize.x, surfaceSize.y);
} else {
drawer.drawOes(frame.textureId, texMatrix, 0, 0, surfaceSize.x, surfaceSize.y);
drawer.drawOes(frame.textureId, texMatrix, frame.rotatedWidth(), frame.rotatedHeight(),
0, 0, surfaceSize.x, surfaceSize.y);
}
eglBase.swapBuffers();

View File

@ -243,7 +243,8 @@ public class VideoRendererGui implements GLSurfaceView.Renderer {
GlUtil.checkNoGLES2Error("glBindFramebuffer");
// Copy the OES texture content. This will also normalize the sampling matrix.
drawer.drawOes(pendingFrame.textureId, rotatedSamplingMatrix,
drawer.drawOes(pendingFrame.textureId, rotatedSamplingMatrix,
textureCopy.getWidth(), textureCopy.getHeight(),
0, 0, textureCopy.getWidth(), textureCopy.getHeight());
rotatedSamplingMatrix = RendererCommon.identityMatrix();
@ -263,10 +264,10 @@ public class VideoRendererGui implements GLSurfaceView.Renderer {
// OpenGL defaults to lower left origin - flip viewport position vertically.
final int viewportY = screenHeight - displayLayout.bottom;
if (rendererType == RendererType.RENDERER_YUV) {
drawer.drawYuv(yuvTextures, texMatrix,
drawer.drawYuv(yuvTextures, texMatrix, videoWidth, videoHeight,
displayLayout.left, viewportY, displayLayout.width(), displayLayout.height());
} else {
drawer.drawRgb(textureCopy.getTextureId(), texMatrix,
drawer.drawRgb(textureCopy.getTextureId(), texMatrix, videoWidth, videoHeight,
displayLayout.left, viewportY, displayLayout.width(), displayLayout.height());
}