From bb7db5a13cd1bfede302d87eb1c36578bfb1e53f Mon Sep 17 00:00:00 2001 From: hschlueter Date: Mon, 25 Jul 2022 22:38:28 +0000 Subject: [PATCH] Only recreate output EGLSurface when Surface changed. PiperOrigin-RevId: 463193768 (cherry picked from commit 5db7778ca322676a6e6445c473184dc1055d4c22) --- ...lMatrixTransformationProcessorWrapper.java | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/libraries/transformer/src/main/java/androidx/media3/transformer/FinalMatrixTransformationProcessorWrapper.java b/libraries/transformer/src/main/java/androidx/media3/transformer/FinalMatrixTransformationProcessorWrapper.java index 1c862ed4f2..ad1b61bf2f 100644 --- a/libraries/transformer/src/main/java/androidx/media3/transformer/FinalMatrixTransformationProcessorWrapper.java +++ b/libraries/transformer/src/main/java/androidx/media3/transformer/FinalMatrixTransformationProcessorWrapper.java @@ -75,6 +75,9 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; @Nullable private SurfaceViewWrapper debugSurfaceViewWrapper; private @MonotonicNonNull Listener listener; private @MonotonicNonNull Size outputSizeBeforeSurfaceTransformation; + private @MonotonicNonNull SurfaceView debugSurfaceView; + + private volatile boolean outputSizeOrRotationChanged; @GuardedBy("this") @Nullable @@ -207,7 +210,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; SurfaceInfo outputSurfaceInfo = this.outputSurfaceInfo; @Nullable EGLSurface outputEglSurface = this.outputEglSurface; - if (outputEglSurface == null) { // This means that outputSurfaceInfo changed. + if (outputEglSurface == null) { if (useHdr) { outputEglSurface = GlUtil.getEglSurfaceRgba1010102(eglDisplay, outputSurfaceInfo.surface); } else { @@ -218,16 +221,17 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; SurfaceView debugSurfaceView = debugViewProvider.getDebugPreviewSurfaceView( outputSurfaceInfo.width, outputSurfaceInfo.height); - if (debugSurfaceView != null) { + if (debugSurfaceView != null && !Util.areEqual(this.debugSurfaceView, debugSurfaceView)) { debugSurfaceViewWrapper = new SurfaceViewWrapper(eglDisplay, eglContext, useHdr, debugSurfaceView); } - if (matrixTransformationProcessor != null) { - matrixTransformationProcessor.release(); - matrixTransformationProcessor = null; - } } + if (matrixTransformationProcessor != null && outputSizeOrRotationChanged) { + matrixTransformationProcessor.release(); + matrixTransformationProcessor = null; + outputSizeOrRotationChanged = false; + } if (matrixTransformationProcessor == null) { matrixTransformationProcessor = createMatrixTransformationProcessorForOutputSurface(outputSurfaceInfo); @@ -316,8 +320,18 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; public synchronized void setOutputSurfaceInfo(@Nullable SurfaceInfo outputSurfaceInfo) { if (!Util.areEqual(this.outputSurfaceInfo, outputSurfaceInfo)) { + if (outputSurfaceInfo != null + && this.outputSurfaceInfo != null + && !this.outputSurfaceInfo.surface.equals(outputSurfaceInfo.surface)) { + this.outputEglSurface = null; + } + outputSizeOrRotationChanged = + this.outputSurfaceInfo == null + || outputSurfaceInfo == null + || this.outputSurfaceInfo.width != outputSurfaceInfo.width + || this.outputSurfaceInfo.height != outputSurfaceInfo.height + || this.outputSurfaceInfo.orientationDegrees != outputSurfaceInfo.orientationDegrees; this.outputSurfaceInfo = outputSurfaceInfo; - this.outputEglSurface = null; } }