diff options
author | Magnus Jedvert <magjed@webrtc.org> | 2015-09-30 18:24:54 +0200 |
---|---|---|
committer | Magnus Jedvert <magjed@webrtc.org> | 2015-09-30 16:25:22 +0000 |
commit | 27551c95744be6e888652b3292b4130cc804f59f (patch) | |
tree | 99aa426b5afc19ecd0a0020fcf469dbd12d67fca /talk/app/webrtc/java/android/org/webrtc/RendererCommon.java | |
parent | 4a8e9c556af602ad6860df7d23247d0e2efe0cc2 (diff) | |
download | webrtc-27551c95744be6e888652b3292b4130cc804f59f.tar.gz |
Android RendererCommon: Refactor getSamplingMatrix()
This CL refactors RendererCommon.getSamplingMatrix() so it does not have any dependecy to SurfaceTeture. The purpose is to prepare for a change in how texture frames are represented - only the texture matrix will be exposed, not the SurfaceTexture itself. This CL also adds an extra test for RendererCommon.rotateTextureMatrix().
R=hbos@webrtc.org
Review URL: https://codereview.webrtc.org/1375593002 .
Cr-Commit-Position: refs/heads/master@{#10118}
Diffstat (limited to 'talk/app/webrtc/java/android/org/webrtc/RendererCommon.java')
-rw-r--r-- | talk/app/webrtc/java/android/org/webrtc/RendererCommon.java | 52 |
1 files changed, 27 insertions, 25 deletions
diff --git a/talk/app/webrtc/java/android/org/webrtc/RendererCommon.java b/talk/app/webrtc/java/android/org/webrtc/RendererCommon.java index 5195044a82..fec41c12e9 100644 --- a/talk/app/webrtc/java/android/org/webrtc/RendererCommon.java +++ b/talk/app/webrtc/java/android/org/webrtc/RendererCommon.java @@ -28,7 +28,6 @@ package org.webrtc; import android.graphics.Point; -import android.graphics.SurfaceTexture; import android.opengl.Matrix; /** @@ -61,37 +60,40 @@ public class RendererCommon { // The minimum fraction of the frame content that will be shown for |SCALE_ASPECT_BALANCED|. // This limits excessive cropping when adjusting display size. private static float BALANCED_VISIBLE_FRACTION = 0.5625f; + public static final float[] identityMatrix() { + return new float[] { + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1}; + } // Matrix with transform y' = 1 - y. - private static final float[] VERTICAL_FLIP = new float[] { - 1, 0, 0, 0, - 0, -1, 0, 0, - 0, 0, 1, 0, - 0, 1, 0, 1}; + public static final float[] verticalFlipMatrix() { + return new float[] { + 1, 0, 0, 0, + 0, -1, 0, 0, + 0, 0, 1, 0, + 0, 1, 0, 1}; + } /** - * Returns matrix that transforms standard coordinates to their proper sampling locations in - * the texture. This transform compensates for any properties of the video source that - * cause it to appear different from a normalized texture. If the video source is based on - * ByteBuffers, pass null in |surfaceTexture|. + * Returns texture matrix that will have the effect of rotating the frame |rotationDegree| + * clockwise when rendered. */ - public static float[] getSamplingMatrix(SurfaceTexture surfaceTexture, float rotationDegree) { - final float[] samplingMatrix; - if (surfaceTexture == null) { - // For ByteBuffers, row 0 specifies the top row, but for a texture, row 0 specifies the - // bottom row. Flip the image vertically to compensate for this. - samplingMatrix = VERTICAL_FLIP; - } else { - samplingMatrix = new float[16]; - surfaceTexture.getTransformMatrix(samplingMatrix); - } - // Clockwise rotation matrix in the XY-plane (around the Z-axis). + public static float[] rotateTextureMatrix(float[] textureMatrix, float rotationDegree) { final float[] rotationMatrix = new float[16]; Matrix.setRotateM(rotationMatrix, 0, rotationDegree, 0, 0, 1); adjustOrigin(rotationMatrix); - // Multiply matrices together. - final float[] tmpMatrix = new float[16]; - Matrix.multiplyMM(tmpMatrix, 0, samplingMatrix, 0, rotationMatrix, 0); - return tmpMatrix; + return multiplyMatrices(textureMatrix, rotationMatrix); + } + + /** + * Returns new matrix with the result of a * b. + */ + public static float[] multiplyMatrices(float[] a, float[] b) { + final float[] resultMatrix = new float[16]; + Matrix.multiplyMM(resultMatrix, 0, a, 0, b, 0); + return resultMatrix; } /** |