Create equals method for gainmaps

Gainmaps don't currently have an equals override, only reference equality is checked by Objects.equals(gainmap1, gainmap2). Create an equals method for gainmaps with the fields we care about to ensure we don't incur false positives in our equality checks.

PiperOrigin-RevId: 635510451
This commit is contained in:
tofunmi 2024-05-20 11:03:46 -07:00 committed by Copybara-Service
parent cefc4dcd77
commit c409623ca0
2 changed files with 41 additions and 7 deletions

View File

@ -42,7 +42,6 @@ import com.google.common.collect.ImmutableList;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
/**
@ -153,7 +152,6 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
private ImmutableList<float[]> visiblePolygon;
private @MonotonicNonNull Gainmap lastGainmap;
private int lastGainmapGenerationId;
private int gainmapTexId;
private @C.ColorTransfer int outputColorTransfer;
@ -453,7 +451,6 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
tempResultMatrix = new float[16];
visiblePolygon = NDC_SQUARE;
gainmapTexId = C.INDEX_UNSET;
lastGainmapGenerationId = C.INDEX_UNSET;
}
private static GlProgram createGlProgram(
@ -533,13 +530,10 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
if (!useHdr) {
return;
}
int gainmapGenerationId = gainmap.getGainmapContents().getGenerationId();
if (Objects.equals(this.lastGainmap, gainmap)
&& gainmapGenerationId == this.lastGainmapGenerationId) {
if (lastGainmap != null && GainmapUtil.equals(this.lastGainmap, gainmap)) {
return;
}
this.lastGainmap = gainmap;
this.lastGainmapGenerationId = gainmapGenerationId;
if (gainmapTexId == C.INDEX_UNSET) {
gainmapTexId = GlUtil.createTexture(gainmap.getGainmapContents());
} else {

View File

@ -0,0 +1,40 @@
package androidx.media3.effect;
/*
* Copyright 2024 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
*
* http://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.
*/
import android.graphics.Gainmap;
import androidx.annotation.RequiresApi;
import androidx.media3.common.util.UnstableApi;
/** Utilities for Gainmaps. */
@UnstableApi
/* package */ class GainmapUtil {
private GainmapUtil() {}
/** Checks whether the contents and fields relevant to effects processing are equal. */
@RequiresApi(34)
public static boolean equals(Gainmap g1, Gainmap g2) {
return g1.getGamma() == g2.getGamma()
&& g1.getRatioMax() == g2.getRatioMax()
&& g1.getRatioMin() == g2.getRatioMin()
&& g1.getEpsilonHdr() == g2.getEpsilonHdr()
&& g1.getEpsilonSdr() == g2.getEpsilonSdr()
&& g1.getDisplayRatioForFullHdr() == g2.getDisplayRatioForFullHdr()
&& g1.getMinDisplayRatioForHdrTransition() == g2.getMinDisplayRatioForHdrTransition()
&& g1.getGainmapContents() == g2.getGainmapContents()
&& g1.getGainmapContents().getGenerationId() == g2.getGainmapContents().getGenerationId();
}
}