From 62604e4d29627e8a69320549204ba025ee9c30b8 Mon Sep 17 00:00:00 2001 From: John Reck Date: Wed, 10 Mar 2021 12:59:39 -0500 Subject: Extend setBrightness to pass SDR & HDR info Test: builds & boots Bug: 182312559 Change-Id: Ic8dd38c3a182efb0687c891379db91a36301f05e --- core/java/android/view/SurfaceControl.java | 52 ++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 7 deletions(-) (limited to 'core/java/android/view/SurfaceControl.java') diff --git a/core/java/android/view/SurfaceControl.java b/core/java/android/view/SurfaceControl.java index 03dd10050724..0167147a1067 100644 --- a/core/java/android/view/SurfaceControl.java +++ b/core/java/android/view/SurfaceControl.java @@ -200,7 +200,8 @@ public final class SurfaceControl implements Parcelable { private static native void nativeSyncInputWindows(long transactionObj); private static native boolean nativeGetDisplayBrightnessSupport(IBinder displayToken); private static native boolean nativeSetDisplayBrightness(IBinder displayToken, - float brightness); + float sdrBrightness, float sdrBrightnessNits, float displayBrightness, + float displayBrightnessNits); private static native long nativeReadTransactionFromParcel(Parcel in); private static native void nativeWriteTransactionToParcel(long nativeObject, Parcel out); private static native void nativeSetShadowRadius(long transactionObj, long nativeObject, @@ -2405,13 +2406,50 @@ public final class SurfaceControl implements Parcelable { * @hide */ public static boolean setDisplayBrightness(IBinder displayToken, float brightness) { + return setDisplayBrightness(displayToken, brightness, -1, brightness, -1); + } + + /** + * Sets the brightness of a display. + * + * @param displayToken + * The token for the display whose brightness is set. + * @param sdrBrightness + * A number between 0.0f (minimum brightness) and 1.0f (maximum brightness), or -1.0f to + * turn the backlight off. Specifies the desired brightness of SDR content. + * @param sdrBrightnessNits + * The value of sdrBrightness converted to calibrated nits. -1 if this isn't available. + * @param displayBrightness + * A number between 0.0f (minimum brightness) and 1.0f (maximum brightness), or + * -1.0f to turn the backlight off. Specifies the desired brightness of the display itself, + * used directly for HDR content. + * @param displayBrightnessNits + * The value of displayBrightness converted to calibrated nits. -1 if this isn't + * available. + * + * @return Whether the method succeeded or not. + * + * @throws IllegalArgumentException if: + * - displayToken is null; + * - brightness is NaN or greater than 1.0f. + * + * @hide + */ + public static boolean setDisplayBrightness(IBinder displayToken, float sdrBrightness, + float sdrBrightnessNits, float displayBrightness, float displayBrightnessNits) { Objects.requireNonNull(displayToken); - if (Float.isNaN(brightness) || brightness > 1.0f - || (brightness < 0.0f && brightness != -1.0f)) { - throw new IllegalArgumentException("brightness must be a number between 0.0f and 1.0f," - + " or -1 to turn the backlight off: " + brightness); - } - return nativeSetDisplayBrightness(displayToken, brightness); + if (Float.isNaN(displayBrightness) || displayBrightness > 1.0f + || (displayBrightness < 0.0f && displayBrightness != -1.0f)) { + throw new IllegalArgumentException("displayBrightness must be a number between 0.0f " + + " and 1.0f, or -1 to turn the backlight off: " + displayBrightness); + } + if (Float.isNaN(sdrBrightness) || sdrBrightness > 1.0f + || (sdrBrightness < 0.0f && sdrBrightness != -1.0f)) { + throw new IllegalArgumentException("sdrBrightness must be a number between 0.0f " + + "and 1.0f, or -1 to turn the backlight off: " + displayBrightness); + } + return nativeSetDisplayBrightness(displayToken, sdrBrightness, sdrBrightnessNits, + displayBrightness, displayBrightnessNits); } /** -- cgit v1.2.3