diff options
| author | 2021-03-17 02:01:53 +0000 | |
|---|---|---|
| committer | 2021-03-17 02:01:53 +0000 | |
| commit | c415157f45fb73f0d55b2a8990332d71c5b900ae (patch) | |
| tree | 71f30a739097e8126a245773b13338d088f10d7d | |
| parent | 8017e2b6dde255b2bb3f21e369b3f5d27e4f3d6e (diff) | |
| parent | 62604e4d29627e8a69320549204ba025ee9c30b8 (diff) | |
Merge "Extend setBrightness to pass SDR & HDR info" into sc-dev
| -rw-r--r-- | core/java/android/view/SurfaceControl.java | 52 | ||||
| -rw-r--r-- | core/jni/android_view_SurfaceControl.cpp | 10 |
2 files changed, 53 insertions, 9 deletions
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); } /** diff --git a/core/jni/android_view_SurfaceControl.cpp b/core/jni/android_view_SurfaceControl.cpp index 31cc77f74c44..65b8b988f38b 100644 --- a/core/jni/android_view_SurfaceControl.cpp +++ b/core/jni/android_view_SurfaceControl.cpp @@ -1528,11 +1528,17 @@ static jboolean nativeGetDisplayBrightnessSupport(JNIEnv* env, jclass clazz, } static jboolean nativeSetDisplayBrightness(JNIEnv* env, jclass clazz, jobject displayTokenObject, - jfloat brightness) { + jfloat sdrBrightness, jfloat sdrBrightnessNits, + jfloat displayBrightness, jfloat displayBrightnessNits) { sp<IBinder> displayToken(ibinderForJavaObject(env, displayTokenObject)); if (displayToken == nullptr) { return JNI_FALSE; } + gui::DisplayBrightness brightness; + brightness.sdrWhitePoint = sdrBrightness; + brightness.sdrWhitePointNits = sdrBrightnessNits; + brightness.displayBrightness = displayBrightness; + brightness.displayBrightnessNits = displayBrightnessNits; status_t error = SurfaceComposerClient::setDisplayBrightness(displayToken, brightness); return error == OK ? JNI_TRUE : JNI_FALSE; } @@ -1860,7 +1866,7 @@ static const JNINativeMethod sSurfaceControlMethods[] = { (void*)nativeSyncInputWindows }, {"nativeGetDisplayBrightnessSupport", "(Landroid/os/IBinder;)Z", (void*)nativeGetDisplayBrightnessSupport }, - {"nativeSetDisplayBrightness", "(Landroid/os/IBinder;F)Z", + {"nativeSetDisplayBrightness", "(Landroid/os/IBinder;FFFF)Z", (void*)nativeSetDisplayBrightness }, {"nativeReadTransactionFromParcel", "(Landroid/os/Parcel;)J", (void*)nativeReadTransactionFromParcel }, |