From f2cfb14be4af9083b565dbc7b60d6de191721e7a Mon Sep 17 00:00:00 2001 From: huangdarwin Date: Thu, 2 Feb 2023 19:54:28 +0000 Subject: [PATCH] HDR: Fix debug surface by setting correct output color. Set the correct output color on the debug SurfaceViewWrapper, so that SDR contents can have an output transfer of either GAMMA_2_2 (Gamma 2.2) or SDR (SMPTE 170M). This fixes an issue where in-app tone-mapping would output gamma 2.2, and the SDR value incorrectly hardcoded here would lead to an error in the OpenGL, which does not support SMPTE 170M. PiperOrigin-RevId: 506684602 --- .../effect/FinalMatrixTextureProcessorWrapper.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/libraries/effect/src/main/java/androidx/media3/effect/FinalMatrixTextureProcessorWrapper.java b/libraries/effect/src/main/java/androidx/media3/effect/FinalMatrixTextureProcessorWrapper.java index 57a0bb11b0..bc6ee16cc3 100644 --- a/libraries/effect/src/main/java/androidx/media3/effect/FinalMatrixTextureProcessorWrapper.java +++ b/libraries/effect/src/main/java/androidx/media3/effect/FinalMatrixTextureProcessorWrapper.java @@ -367,7 +367,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; if (debugSurfaceView != null && !Util.areEqual(this.debugSurfaceView, debugSurfaceView)) { debugSurfaceViewWrapper = new SurfaceViewWrapper( - eglDisplay, eglContext, ColorInfo.isTransferHdr(outputColorInfo), debugSurfaceView); + eglDisplay, eglContext, debugSurfaceView, outputColorInfo.colorTransfer); } this.debugSurfaceView = debugSurfaceView; } @@ -467,11 +467,17 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; private int height; public SurfaceViewWrapper( - EGLDisplay eglDisplay, EGLContext eglContext, boolean useHdr, SurfaceView surfaceView) { + EGLDisplay eglDisplay, + EGLContext eglContext, + SurfaceView surfaceView, + @C.ColorTransfer int outputColorTransfer) { this.eglDisplay = eglDisplay; this.eglContext = eglContext; // Screen output supports only BT.2020 PQ (ST2084) for HDR. - this.outputColorTransfer = useHdr ? C.COLOR_TRANSFER_ST2084 : C.COLOR_TRANSFER_SDR; + this.outputColorTransfer = + outputColorTransfer == C.COLOR_TRANSFER_HLG + ? C.COLOR_TRANSFER_ST2084 + : outputColorTransfer; surfaceView.getHolder().addCallback(this); surface = surfaceView.getHolder().getSurface(); width = surfaceView.getWidth();