Fix resizing in debug preview

PiperOrigin-RevId: 732905018
This commit is contained in:
Googler 2025-03-03 06:46:43 -08:00 committed by Copybara-Service
parent 86df7572d2
commit 1e4a10651a

View File

@ -68,6 +68,8 @@ public final class DebugViewShaderProgram implements GlShaderProgram {
private Executor errorListenerExecutor; private Executor errorListenerExecutor;
private @MonotonicNonNull EGLDisplay eglDisplay; private @MonotonicNonNull EGLDisplay eglDisplay;
private int outputWidth = C.LENGTH_UNSET;
private int outputHeight = C.LENGTH_UNSET;
public DebugViewShaderProgram( public DebugViewShaderProgram(
Context context, DebugViewProvider debugViewProvider, ColorInfo outputColorInfo) { Context context, DebugViewProvider debugViewProvider, ColorInfo outputColorInfo) {
@ -154,9 +156,13 @@ public final class DebugViewShaderProgram implements GlShaderProgram {
eglDisplay = getDefaultEglDisplay(); eglDisplay = getDefaultEglDisplay();
} }
EGLContext eglContext = GlUtil.getCurrentContext(); EGLContext eglContext = GlUtil.getCurrentContext();
if (outputWidth == C.LENGTH_UNSET || outputHeight == C.LENGTH_UNSET) {
outputWidth = inputWidth;
outputHeight = inputHeight;
}
@Nullable @Nullable
SurfaceView debugSurfaceView = SurfaceView debugSurfaceView =
debugViewProvider.getDebugPreviewSurfaceView(inputWidth, inputHeight); debugViewProvider.getDebugPreviewSurfaceView(outputWidth, outputHeight);
if (debugSurfaceView != null && !Objects.equals(this.debugSurfaceView, debugSurfaceView)) { if (debugSurfaceView != null && !Objects.equals(this.debugSurfaceView, debugSurfaceView)) {
debugSurfaceViewWrapper = debugSurfaceViewWrapper =
new SurfaceViewWrapper( new SurfaceViewWrapper(
@ -164,10 +170,16 @@ public final class DebugViewShaderProgram implements GlShaderProgram {
} }
this.debugSurfaceView = debugSurfaceView; this.debugSurfaceView = debugSurfaceView;
if (defaultShaderProgram == null) { if (defaultShaderProgram == null) {
ImmutableList.Builder<GlMatrixTransformation> matrixTransformationListBuilder =
new ImmutableList.Builder<>();
matrixTransformationListBuilder.add(
Presentation.createForWidthAndHeight(
outputWidth, outputHeight, Presentation.LAYOUT_SCALE_TO_FIT));
defaultShaderProgram = defaultShaderProgram =
DefaultShaderProgram.createApplyingOetf( DefaultShaderProgram.createApplyingOetf(
context, context,
/* matrixTransformations= */ ImmutableList.of(), /* matrixTransformations= */ matrixTransformationListBuilder.build(),
/* rgbMatrices= */ ImmutableList.of(), /* rgbMatrices= */ ImmutableList.of(),
outputColorInfo, outputColorInfo,
outputColorInfo.colorTransfer == C.COLOR_TRANSFER_LINEAR outputColorInfo.colorTransfer == C.COLOR_TRANSFER_LINEAR