From c7102ea5d2e3308498de7e5f6c403eca8ccc1967 Mon Sep 17 00:00:00 2001 From: John Reck Date: Wed, 25 Jan 2023 13:28:04 -0500 Subject: [PATCH] Add extended range brightness API Internal for now TODO: Make public Bug: 241001465 Test: manual, flagged off currently Change-Id: I8b129437ab87593741d36a7fada56a9ebf7deaad --- core/java/android/view/SurfaceControl.java | 42 ++++++++++++++++++++++ core/jni/android_view_SurfaceControl.cpp | 10 ++++++ 2 files changed, 52 insertions(+) diff --git a/core/java/android/view/SurfaceControl.java b/core/java/android/view/SurfaceControl.java index 5c23c3150bd3d..fedb09823a994 100644 --- a/core/java/android/view/SurfaceControl.java +++ b/core/java/android/view/SurfaceControl.java @@ -222,6 +222,8 @@ public final class SurfaceControl implements Parcelable { int transform); private static native void nativeSetDataSpace(long transactionObj, long nativeObject, @DataSpace.NamedDataSpace int dataSpace); + private static native void nativeSetExtendedRangeBrightness(long transactionObj, + long nativeObject, float currentBufferRatio, float desiredRatio); private static native void nativeSetDamageRegion(long transactionObj, long nativeObject, Region region); private static native void nativeSetDimmingEnabled(long transactionObj, long nativeObject, @@ -3609,6 +3611,46 @@ public final class SurfaceControl implements Parcelable { return this; } + /** + * Sets the desired extended range brightness for the layer. This only applies for layers + * whose dataspace has RANGE_EXTENDED. + * + * @param sc The layer whose extended range brightness is being specified + * @param currentBufferRatio The current sdr/hdr ratio of the current buffer. For example + * if the buffer was rendered with a target SDR whitepoint of + * 100 nits and a max display brightness of 200 nits, this should + * be set to 2.0f. + * + * Default value is 1.0f. + * + * Transfer functions that encode their own brightness ranges, + * such as HLG or PQ, should also set this to 1.0f and instead + * communicate extended content brightness information via + * metadata such as CTA861_3 or SMPTE2086. + * + * @param desiredRatio The desired sdr/hdr ratio. This can be used to communicate the max + * desired brightness range. This is similar to the "max luminance" + * value in other HDR metadata formats, but represented as a ratio of + * the target SDR whitepoint to the max display brightness. The system + * may not be able to, or may choose not to, deliver the + * requested range. + * + * If unspecified, the system will attempt to provide the best range + * it can for the given ambient conditions & device state. However, + * voluntarily reducing the requested range can help improve battery + * life as well as can improve quality by ensuring greater bit depth + * is allocated to the luminance range in use. + * @return this + * @hide + **/ + public @NonNull Transaction setExtendedRangeBrightness(@NonNull SurfaceControl sc, + float currentBufferRatio, float desiredRatio) { + checkPreconditions(sc); + nativeSetExtendedRangeBrightness(mNativeObject, sc.mNativeObject, currentBufferRatio, + desiredRatio); + return this; + } + /** * Sets the trusted overlay state on this SurfaceControl and it is inherited to all the * children. The caller must hold the ACCESS_SURFACE_FLINGER permission. diff --git a/core/jni/android_view_SurfaceControl.cpp b/core/jni/android_view_SurfaceControl.cpp index 34589b7c95858..225ed2cff7624 100644 --- a/core/jni/android_view_SurfaceControl.cpp +++ b/core/jni/android_view_SurfaceControl.cpp @@ -579,6 +579,14 @@ static void nativeSetDataSpace(JNIEnv* env, jclass clazz, jlong transactionObj, transaction->setDataspace(ctrl, dataspace); } +static void nativeSetExtendedRangeBrightness(JNIEnv* env, jclass clazz, jlong transactionObj, + jlong nativeObject, float currentBufferRatio, + float desiredRatio) { + auto transaction = reinterpret_cast(transactionObj); + SurfaceControl* const ctrl = reinterpret_cast(nativeObject); + transaction->setExtendedRangeBrightness(ctrl, currentBufferRatio, desiredRatio); +} + static void nativeSetBlurRegions(JNIEnv* env, jclass clazz, jlong transactionObj, jlong nativeObject, jobjectArray regions, jint regionsLength) { auto transaction = reinterpret_cast(transactionObj); @@ -2086,6 +2094,8 @@ static const JNINativeMethod sSurfaceControlMethods[] = { {"nativeSetBufferTransform", "(JJI)V", (void*) nativeSetBufferTransform}, {"nativeSetDataSpace", "(JJI)V", (void*)nativeSetDataSpace }, + {"nativeSetExtendedRangeBrightness", "(JJFF)V", + (void*)nativeSetExtendedRangeBrightness }, {"nativeAddWindowInfosReportedListener", "(JLjava/lang/Runnable;)V", (void*)nativeAddWindowInfosReportedListener }, {"nativeGetDisplayBrightnessSupport", "(Landroid/os/IBinder;)Z",