Correctly pass drawn frame size when layout aspect ratio is used in EglRenderer.
Previously, layout matrix was not correctly taken into account when calculating
the drawn size of the frame.
BUG=webrtc:6470
Review-Url: https://codereview.webrtc.org/2514793002
Cr-Commit-Position: refs/heads/master@{#15163}
diff --git a/webrtc/api/android/java/src/org/webrtc/EglRenderer.java b/webrtc/api/android/java/src/org/webrtc/EglRenderer.java
index 65961bb..b6dd649 100644
--- a/webrtc/api/android/java/src/org/webrtc/EglRenderer.java
+++ b/webrtc/api/android/java/src/org/webrtc/EglRenderer.java
@@ -533,6 +533,8 @@
// After a surface size change, the EGLSurface might still have a buffer of the old size in the
// pipeline. Querying the EGLSurface will show if the underlying buffer dimensions haven't yet
// changed. Such a buffer will be rendered incorrectly, so flush it with a black frame.
+ final int drawnFrameWidth;
+ final int drawnFrameHeight;
synchronized (layoutLock) {
int surfaceClearCount = 0;
while (eglBase.surfaceWidth() != surfaceWidth || eglBase.surfaceHeight() != surfaceHeight) {
@@ -548,11 +550,20 @@
}
final float[] layoutMatrix;
if (layoutAspectRatio > 0) {
- layoutMatrix = RendererCommon.getLayoutMatrix(
- mirror, frame.rotatedWidth() / (float) frame.rotatedHeight(), layoutAspectRatio);
+ final float frameAspectRatio = frame.rotatedWidth() / (float) frame.rotatedHeight();
+ layoutMatrix = RendererCommon.getLayoutMatrix(mirror, frameAspectRatio, layoutAspectRatio);
+ if (frameAspectRatio > layoutAspectRatio) {
+ drawnFrameWidth = (int) (frame.rotatedHeight() * layoutAspectRatio);
+ drawnFrameHeight = frame.rotatedHeight();
+ } else {
+ drawnFrameWidth = frame.rotatedWidth();
+ drawnFrameHeight = (int) (frame.rotatedWidth() / layoutAspectRatio);
+ }
} else {
layoutMatrix =
mirror ? RendererCommon.horizontalFlipMatrix() : RendererCommon.identityMatrix();
+ drawnFrameWidth = frame.rotatedWidth();
+ drawnFrameHeight = frame.rotatedHeight();
}
drawMatrix = RendererCommon.multiplyMatrices(texMatrix, layoutMatrix);
}
@@ -567,12 +578,13 @@
yuvTextures[i] = GlUtil.generateTexture(GLES20.GL_TEXTURE_2D);
}
}
+
yuvUploader.uploadYuvData(
yuvTextures, frame.width, frame.height, frame.yuvStrides, frame.yuvPlanes);
- drawer.drawYuv(yuvTextures, drawMatrix, frame.rotatedWidth(), frame.rotatedHeight(), 0, 0,
- surfaceWidth, surfaceHeight);
+ drawer.drawYuv(yuvTextures, drawMatrix, drawnFrameWidth, drawnFrameHeight, 0, 0, surfaceWidth,
+ surfaceHeight);
} else {
- drawer.drawOes(frame.textureId, drawMatrix, frame.rotatedWidth(), frame.rotatedHeight(), 0, 0,
+ drawer.drawOes(frame.textureId, drawMatrix, drawnFrameWidth, drawnFrameHeight, 0, 0,
surfaceWidth, surfaceHeight);
}