Overlay: fix the overlay anchor translation

Makes OverlayFrameAnchor works as described in the OverlaySettings documentation. Currently the code does the opposite e.g setting the anchor to (+1,-1) makes the code anchor to the top left rather than the bottom right.

PiperOrigin-RevId: 621585558
This commit is contained in:
tofunmi 2024-04-03 11:22:59 -07:00 committed by Copybara-Service
parent 60bb24a930
commit 896d147444
5 changed files with 10 additions and 15 deletions

View File

@ -102,6 +102,11 @@
* Add support for EGL_GL_COLORSPACE_BT2020_HLG_EXT, which improves HLG
surface output in ExoPlayer.setVideoEffect and Transformer's Debug
SurfaceView.
* Update Overlay matrix implementation to make it consistent with the
documentation by flipping the x and y values applied in
`setOverlayFrameAnchor()`. If using
`OverlaySettings.Builder.setOverlayFrameAnchor()`, please flip their x
and y values by multiplying them by `-1`.
* Muxers:
* IMA extension:
* Session:

View File

@ -38,7 +38,7 @@ import java.util.Locale;
new OverlaySettings.Builder()
// Place the timer in the bottom left corner of the screen with some padding from the
// edges.
.setOverlayFrameAnchor(/* x= */ 1f, /* y= */ 1f)
.setOverlayFrameAnchor(/* x= */ -1f, /* y= */ -1f)
.setBackgroundFrameAnchor(/* x= */ -0.7f, /* y= */ -0.95f)
.build();
}

View File

@ -623,7 +623,7 @@ public final class TransformerActivity extends AppCompatActivity {
new OverlaySettings.Builder()
// Place the logo in the bottom left corner of the screen with some padding from the
// edges.
.setOverlayFrameAnchor(/* x= */ 1f, /* y= */ 1f)
.setOverlayFrameAnchor(/* x= */ -1f, /* y= */ -1f)
.setBackgroundFrameAnchor(/* x= */ -0.95f, /* y= */ -0.95f)
.build();
Drawable logo;

View File

@ -171,7 +171,7 @@ public class OverlayShaderProgramPixelTest {
Bitmap overlayBitmap = readBitmap(OVERLAY_PNG_ASSET_PATH);
OverlaySettings overlaySettings =
new OverlaySettings.Builder()
.setOverlayFrameAnchor(/* x= */ 1f, /* y= */ -1f)
.setOverlayFrameAnchor(/* x= */ -1f, /* y= */ 1f)
.setBackgroundFrameAnchor(/* x= */ -1f, /* y= */ 1f)
.build();
BitmapOverlay staticBitmapOverlay =
@ -199,7 +199,7 @@ public class OverlayShaderProgramPixelTest {
throws Exception {
Bitmap overlayBitmap = readBitmap(OVERLAY_PNG_ASSET_PATH);
OverlaySettings overlaySettings =
new OverlaySettings.Builder().setOverlayFrameAnchor(/* x= */ 1f, /* y= */ -1f).build();
new OverlaySettings.Builder().setOverlayFrameAnchor(/* x= */ -1f, /* y= */ 1f).build();
BitmapOverlay staticBitmapOverlay =
BitmapOverlay.createStaticBitmapOverlay(overlayBitmap, overlaySettings);
overlayShaderProgram =

View File

@ -33,23 +33,13 @@ import androidx.media3.common.util.Size;
@Override
public float[] getTransformationMatrix(Size overlaySize, OverlaySettings overlaySettings) {
// When sampling from a (for example, texture) sampler, the overlay anchor's x and y coordinates
// are flipped.
OverlaySettings samplerOverlaySettings =
overlaySettings
.buildUpon()
.setOverlayFrameAnchor(
/* x= */ -1 * overlaySettings.overlayFrameAnchor.first,
/* y= */ -1 * overlaySettings.overlayFrameAnchor.second)
.build();
// When sampling from a (for example, texture) sampler, the transformation matrix applied to a
// sampler's coordinate should be the inverse of the transformation matrix that would otherwise
// be applied to a vertex.
Matrix.invertM(
transformationMatrixInv,
MATRIX_OFFSET,
super.getTransformationMatrix(overlaySize, samplerOverlaySettings),
super.getTransformationMatrix(overlaySize, overlaySettings),
MATRIX_OFFSET);
return transformationMatrixInv;
}