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 * Add support for EGL_GL_COLORSPACE_BT2020_HLG_EXT, which improves HLG
surface output in ExoPlayer.setVideoEffect and Transformer's Debug surface output in ExoPlayer.setVideoEffect and Transformer's Debug
SurfaceView. 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: * Muxers:
* IMA extension: * IMA extension:
* Session: * Session:

View File

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

View File

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

View File

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

View File

@ -33,23 +33,13 @@ import androidx.media3.common.util.Size;
@Override @Override
public float[] getTransformationMatrix(Size overlaySize, OverlaySettings overlaySettings) { 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 // 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 // sampler's coordinate should be the inverse of the transformation matrix that would otherwise
// be applied to a vertex. // be applied to a vertex.
Matrix.invertM( Matrix.invertM(
transformationMatrixInv, transformationMatrixInv,
MATRIX_OFFSET, MATRIX_OFFSET,
super.getTransformationMatrix(overlaySize, samplerOverlaySettings), super.getTransformationMatrix(overlaySize, overlaySettings),
MATRIX_OFFSET); MATRIX_OFFSET);
return transformationMatrixInv; return transformationMatrixInv;
} }