media/libraries/effect/src/main/java/androidx/media3/effect/SamplerOverlayMatrixProvider.java
tofunmi 896d147444 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
2024-04-03 11:27:43 -07:00

46 lines
1.6 KiB
Java

/*
* Copyright 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package androidx.media3.effect;
import android.opengl.Matrix;
import androidx.media3.common.util.GlUtil;
import androidx.media3.common.util.Size;
/**
* Provides a matrix based on {@link OverlaySettings} to be applied on a texture sampling
* coordinate.
*/
/* package */ final class SamplerOverlayMatrixProvider extends OverlayMatrixProvider {
private final float[] transformationMatrixInv;
public SamplerOverlayMatrixProvider() {
super();
transformationMatrixInv = GlUtil.create4x4IdentityMatrix();
}
@Override
public float[] getTransformationMatrix(Size overlaySize, OverlaySettings overlaySettings) {
// 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, overlaySettings),
MATRIX_OFFSET);
return transformationMatrixInv;
}
}