Reland of Android GlDrawer: Add frame size as argument to draw functions (patchset #1 id:1 of https://codereview.webrtc.org/1950953002/ )
Reason for revert: I was too quick to judge, this CL does not cause the problem. Original issue's description: > Revert of Android GlDrawer: Add frame size as argument to draw functions (patchset #2 id:20001 of https://codereview.webrtc.org/1948473002/ ) > > Reason for revert: > Causes errors on Google3 import. > > Original issue's description: > > Android GlDrawer: Add frame size as argument to draw functions > > > > BUG=b/28544933 > > > > Committed: https://crrev.com/71af75dc3ca8516017dca9de2ebe582145ecad14 > > Cr-Commit-Position: refs/heads/master@{#12623} > > TBR=glaznev@webrtc.org,magjed@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=b/28544933 > > Committed: https://crrev.com/172683173dd84a72659ad494962245445eb2a353 > Cr-Commit-Position: refs/heads/master@{#12627} TBR=glaznev@webrtc.org,magjed@webrtc.org # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=b/28544933 Review-Url: https://codereview.webrtc.org/1947073002 Cr-Commit-Position: refs/heads/master@{#12628}
This commit is contained in:
@ -98,7 +98,8 @@ public final class GlRectDrawerTest extends ActivityTestCase {
|
||||
|
||||
// Draw the RGB frame onto the pixel buffer.
|
||||
final GlRectDrawer drawer = new GlRectDrawer();
|
||||
drawer.drawRgb(rgbTexture, RendererCommon.identityMatrix(), 0, 0, WIDTH, HEIGHT);
|
||||
drawer.drawRgb(rgbTexture, RendererCommon.identityMatrix(), WIDTH, HEIGHT,
|
||||
0 /* viewportX */, 0 /* viewportY */, WIDTH, HEIGHT);
|
||||
|
||||
// Download the pixels in the pixel buffer as RGBA. Not all platforms support RGB, e.g. Nexus 9.
|
||||
final ByteBuffer rgbaData = ByteBuffer.allocateDirect(WIDTH * HEIGHT * 4);
|
||||
@ -145,7 +146,8 @@ public final class GlRectDrawerTest extends ActivityTestCase {
|
||||
|
||||
// Draw the YUV frame onto the pixel buffer.
|
||||
final GlRectDrawer drawer = new GlRectDrawer();
|
||||
drawer.drawYuv(yuvTextures, RendererCommon.identityMatrix(), 0, 0, WIDTH, HEIGHT);
|
||||
drawer.drawYuv(yuvTextures, RendererCommon.identityMatrix(), WIDTH, HEIGHT,
|
||||
0 /* viewportX */, 0 /* viewportY */, WIDTH, HEIGHT);
|
||||
|
||||
// Download the pixels in the pixel buffer as RGBA. Not all platforms support RGB, e.g. Nexus 9.
|
||||
final ByteBuffer data = ByteBuffer.allocateDirect(WIDTH * HEIGHT * 4);
|
||||
@ -233,7 +235,8 @@ public final class GlRectDrawerTest extends ActivityTestCase {
|
||||
GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGB, WIDTH,
|
||||
HEIGHT, 0, GLES20.GL_RGB, GLES20.GL_UNSIGNED_BYTE, rgbPlane);
|
||||
// Draw the RGB data onto the SurfaceTexture.
|
||||
drawer.drawRgb(rgbTexture, RendererCommon.identityMatrix(), 0, 0, WIDTH, HEIGHT);
|
||||
drawer.drawRgb(rgbTexture, RendererCommon.identityMatrix(), WIDTH, HEIGHT,
|
||||
0 /* viewportX */, 0 /* viewportY */, WIDTH, HEIGHT);
|
||||
eglBase.swapBuffers();
|
||||
}
|
||||
|
||||
@ -271,7 +274,8 @@ public final class GlRectDrawerTest extends ActivityTestCase {
|
||||
// Draw the OES texture on the pixel buffer.
|
||||
eglBase.makeCurrent();
|
||||
final GlRectDrawer drawer = new GlRectDrawer();
|
||||
drawer.drawOes(listener.oesTextureId, listener.transformMatrix, 0, 0, WIDTH, HEIGHT);
|
||||
drawer.drawOes(listener.oesTextureId, listener.transformMatrix, WIDTH, HEIGHT,
|
||||
0 /* viewportX */, 0 /* viewportY */, WIDTH, HEIGHT);
|
||||
|
||||
// Download the pixels in the pixel buffer as RGBA. Not all platforms support RGB, e.g. Nexus 9.
|
||||
final ByteBuffer rgbaData = ByteBuffer.allocateDirect(WIDTH * HEIGHT * 4);
|
||||
|
||||
@ -131,7 +131,8 @@ public final class SurfaceTextureHelperTest extends ActivityTestCase {
|
||||
// Wait for an OES texture to arrive and draw it onto the pixel buffer.
|
||||
listener.waitForNewFrame();
|
||||
eglBase.makeCurrent();
|
||||
drawer.drawOes(listener.oesTextureId, listener.transformMatrix, 0, 0, width, height);
|
||||
drawer.drawOes(listener.oesTextureId, listener.transformMatrix, width, height,
|
||||
0, 0, width, height);
|
||||
|
||||
surfaceTextureHelper.returnTextureFrame();
|
||||
|
||||
@ -202,7 +203,8 @@ public final class SurfaceTextureHelperTest extends ActivityTestCase {
|
||||
// Draw the pending texture frame onto the pixel buffer.
|
||||
eglBase.makeCurrent();
|
||||
final GlRectDrawer drawer = new GlRectDrawer();
|
||||
drawer.drawOes(listener.oesTextureId, listener.transformMatrix, 0, 0, width, height);
|
||||
drawer.drawOes(listener.oesTextureId, listener.transformMatrix, width, height,
|
||||
0, 0, width, height);
|
||||
drawer.release();
|
||||
|
||||
// Download the pixels in the pixel buffer as RGBA. Not all platforms support RGB, e.g. Nexus 9.
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -244,6 +244,7 @@ public class VideoRendererGui implements GLSurfaceView.Renderer {
|
||||
|
||||
// Copy the OES texture content. This will also normalize the sampling matrix.
|
||||
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());
|
||||
}
|
||||
|
||||
|
||||
@ -395,7 +395,7 @@ public class MediaCodecVideoEncoder {
|
||||
// TODO(perkj): glClear() shouldn't be necessary since every pixel is covered anyway,
|
||||
// but it's a workaround for bug webrtc:5147.
|
||||
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
|
||||
drawer.drawOes(oesTextureId, transformationMatrix, 0, 0, width, height);
|
||||
drawer.drawOes(oesTextureId, transformationMatrix, width, height, 0, 0, width, height);
|
||||
eglBase.swapBuffers(TimeUnit.MICROSECONDS.toNanos(presentationTimestampUs));
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user