From 078547afdaac372fbf08d2b40c857123ba1c6813 Mon Sep 17 00:00:00 2001 From: Fiona Campbell Date: Mon, 11 Jan 2021 21:59:54 +0000 Subject: [PATCH] Make Brightness Ramp Speeds Configurable Allow brightness ramp speeds to differ based on whether the brightness is increasing or decreasing. They already allow fast / slow ramp rates. If all 4 values (fast up; fast down; slow up; slow down) are put in the DDC, these are used. Otherwise, config.xml provides one value for fast and one for slow ramp rates, these are used for both increasing and decreasing values. Bug: 156247142 Test: manual Change-Id: If0920328e2bf16e3f8ebe6ea1b07a467e5c4e939 --- .../server/display/DisplayDeviceConfig.java | 63 +++++++++++++++++++ .../display/DisplayPowerController.java | 44 ++++++++++--- .../display-device-config.xsd | 12 ++++ .../display-device-config/schema/current.txt | 8 +++ 4 files changed, 117 insertions(+), 10 deletions(-) diff --git a/services/core/java/com/android/server/display/DisplayDeviceConfig.java b/services/core/java/com/android/server/display/DisplayDeviceConfig.java index 68708d36f2594..d6872217eab61 100644 --- a/services/core/java/com/android/server/display/DisplayDeviceConfig.java +++ b/services/core/java/com/android/server/display/DisplayDeviceConfig.java @@ -24,6 +24,7 @@ import android.util.Slog; import android.view.DisplayAddress; import com.android.internal.BrightnessSynchronizer; +import com.android.internal.R; import com.android.server.display.config.DisplayConfiguration; import com.android.server.display.config.DisplayQuirks; import com.android.server.display.config.HbmTiming; @@ -64,6 +65,7 @@ public class DisplayDeviceConfig { private static final String STABLE_ID_SUFFIX_FORMAT = "id_%d"; private static final String NO_SUFFIX_FORMAT = "%d"; private static final long STABLE_FLAG = 1L << 62; + // Float.NaN (used as invalid for brightness) cannot be stored in config.xml // so -2 is used instead private static final float INVALID_BRIGHTNESS_IN_CONFIG = -2f; @@ -75,6 +77,10 @@ public class DisplayDeviceConfig { private float mBrightnessMinimum = Float.NaN; private float mBrightnessMaximum = Float.NaN; private float mBrightnessDefault = Float.NaN; + private float mBrightnessRampFastDecrease = Float.NaN; + private float mBrightnessRampFastIncrease = Float.NaN; + private float mBrightnessRampSlowDecrease = Float.NaN; + private float mBrightnessRampSlowIncrease = Float.NaN; private List mQuirks; private boolean mIsHighBrightnessModeEnabled = false; private HighBrightnessModeData mHbmData; @@ -177,6 +183,22 @@ public class DisplayDeviceConfig { return mBrightnessDefault; } + public float getBrightnessRampFastDecrease() { + return mBrightnessRampFastDecrease; + } + + public float getBrightnessRampFastIncrease() { + return mBrightnessRampFastIncrease; + } + + public float getBrightnessRampSlowDecrease() { + return mBrightnessRampSlowDecrease; + } + + public float getBrightnessRampSlowIncrease() { + return mBrightnessRampSlowIncrease; + } + /** * @param quirkValue The quirk to test. * @return {@code true} if the specified quirk is present in this configuration, @@ -210,6 +232,10 @@ public class DisplayDeviceConfig { + ", mQuirks=" + mQuirks + ", isHbmEnabled=" + mIsHighBrightnessModeEnabled + ", mHbmData=" + mHbmData + + ", mBrightnessRampFastDecrease=" + mBrightnessRampFastDecrease + + ", mBrightnessRampFastIncrease=" + mBrightnessRampFastIncrease + + ", mBrightnessRampSlowDecrease=" + mBrightnessRampSlowDecrease + + ", mBrightnessRampSlowIncrease=" + mBrightnessRampSlowIncrease + "}"; return str; } @@ -265,6 +291,7 @@ public class DisplayDeviceConfig { loadBrightnessConstraintsFromConfigXml(); loadHighBrightnessModeData(config); loadQuirks(config); + loadBrightnessRamps(config); } else { Slog.w(TAG, "DisplayDeviceConfig file is null"); } @@ -278,6 +305,7 @@ public class DisplayDeviceConfig { // If no ddc exists, use config.xml loadBrightnessDefaultFromConfigXml(); loadBrightnessConstraintsFromConfigXml(); + loadBrightnessRampsFromConfigXml(); } private void initFromPmValues() { @@ -397,6 +425,41 @@ public class DisplayDeviceConfig { } } + private void loadBrightnessRamps(DisplayConfiguration config) { + // Priority 1: Value in the display device config (float) + // Priority 2: Value in the config.xml (int) + final BigDecimal fastDownDecimal = config.getScreenBrightnessRampFastDecrease(); + final BigDecimal fastUpDecimal = config.getScreenBrightnessRampFastIncrease(); + final BigDecimal slowDownDecimal = config.getScreenBrightnessRampSlowDecrease(); + final BigDecimal slowUpDecimal = config.getScreenBrightnessRampSlowIncrease(); + + if (fastDownDecimal != null && fastUpDecimal != null && slowDownDecimal != null + && slowUpDecimal != null) { + mBrightnessRampFastDecrease = fastDownDecimal.floatValue(); + mBrightnessRampFastIncrease = fastUpDecimal.floatValue(); + mBrightnessRampSlowDecrease = slowDownDecimal.floatValue(); + mBrightnessRampSlowIncrease = slowUpDecimal.floatValue(); + } else { + if (fastDownDecimal != null || fastUpDecimal != null || slowDownDecimal != null + || slowUpDecimal != null) { + Slog.w(TAG, "Per display brightness ramp values ignored because not all " + + "values are present in display device config"); + } + loadBrightnessRampsFromConfigXml(); + } + } + + private void loadBrightnessRampsFromConfigXml() { + mBrightnessRampFastIncrease = BrightnessSynchronizer.brightnessIntToFloat( + mContext.getResources().getInteger(R.integer.config_brightness_ramp_rate_fast)); + mBrightnessRampSlowIncrease = BrightnessSynchronizer.brightnessIntToFloat( + mContext.getResources().getInteger(R.integer.config_brightness_ramp_rate_slow)); + // config.xml uses the same values for both increasing and decreasing brightness + // transitions so we assign them to the same values here. + mBrightnessRampFastDecrease = mBrightnessRampFastIncrease; + mBrightnessRampSlowDecrease = mBrightnessRampSlowIncrease; + } + /** * Container for high brightness mode configuration data. */ diff --git a/services/core/java/com/android/server/display/DisplayPowerController.java b/services/core/java/com/android/server/display/DisplayPowerController.java index 811625b06cf09..d9ee9a306f071 100644 --- a/services/core/java/com/android/server/display/DisplayPowerController.java +++ b/services/core/java/com/android/server/display/DisplayPowerController.java @@ -331,8 +331,10 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call private BrightnessReason mBrightnessReasonTemp = new BrightnessReason(); // Brightness animation ramp rates in brightness units per second - private final float mBrightnessRampRateSlow; - private final float mBrightnessRampRateFast; + private float mBrightnessRampRateFastDecrease; + private float mBrightnessRampRateFastIncrease; + private float mBrightnessRampRateSlowDecrease; + private float mBrightnessRampRateSlowIncrease; // Whether or not to skip the initial brightness ramps into STATE_ON. @@ -459,10 +461,21 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call mAllowAutoBrightnessWhileDozingConfig = resources.getBoolean( com.android.internal.R.bool.config_allowAutoBrightnessWhileDozing); - mBrightnessRampRateFast = BrightnessSynchronizer.brightnessIntToFloat(resources.getInteger( - com.android.internal.R.integer.config_brightness_ramp_rate_fast)); - mBrightnessRampRateSlow = BrightnessSynchronizer.brightnessIntToFloat(resources.getInteger( - com.android.internal.R.integer.config_brightness_ramp_rate_slow)); + + DisplayDeviceConfig displayDeviceConfig = logicalDisplay + .getPrimaryDisplayDeviceLocked().getDisplayDeviceConfig(); + // TODO: (b/178183143) Ensure that the ddc is not null + if (displayDeviceConfig != null) { + mBrightnessRampRateFastDecrease = displayDeviceConfig.getBrightnessRampFastDecrease(); + mBrightnessRampRateFastIncrease = displayDeviceConfig.getBrightnessRampFastIncrease(); + mBrightnessRampRateSlowDecrease = displayDeviceConfig.getBrightnessRampSlowDecrease(); + mBrightnessRampRateSlowIncrease = displayDeviceConfig.getBrightnessRampSlowIncrease(); + } else { + mBrightnessRampRateFastDecrease = 1.0f; + mBrightnessRampRateFastIncrease = 1.0f; + mBrightnessRampRateSlowDecrease = 1.0f; + mBrightnessRampRateSlowIncrease = 1.0f; + } mSkipScreenOnBrightnessRamp = resources.getBoolean( com.android.internal.R.bool.config_skipScreenOnBrightnessRamp); @@ -772,7 +785,6 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call boolean mustInitialize = false; int brightnessAdjustmentFlags = 0; mBrightnessReasonTemp.set(null); - synchronized (mLock) { mPendingUpdatePowerStateLocked = false; if (mPendingRequestLocked == null) { @@ -1111,13 +1123,25 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call // user even when the display is all black. float animateValue = brightnessState == PowerManager.BRIGHTNESS_OFF_FLOAT ? PowerManager.BRIGHTNESS_MIN : brightnessState; - if (isValidBrightnessValue(animateValue)) { + final float currentBrightness = mPowerState.getScreenBrightness(); + if (isValidBrightnessValue(animateValue) + && !BrightnessSynchronizer.floatEquals(animateValue, currentBrightness)) { if (initialRampSkip || hasBrightnessBuckets || wasOrWillBeInVr || !isDisplayContentVisible || brightnessIsTemporary) { animateScreenBrightness(animateValue, SCREEN_ANIMATION_RATE_MINIMUM); } else { - animateScreenBrightness(animateValue, - slowChange ? mBrightnessRampRateSlow : mBrightnessRampRateFast); + boolean isIncreasing = animateValue > currentBrightness; + final float rampSpeed; + if (isIncreasing && slowChange) { + rampSpeed = mBrightnessRampRateSlowIncrease; + } else if (isIncreasing && !slowChange) { + rampSpeed = mBrightnessRampRateFastIncrease; + } else if (!isIncreasing && slowChange) { + rampSpeed = mBrightnessRampRateSlowDecrease; + } else { + rampSpeed = mBrightnessRampRateFastDecrease; + } + animateScreenBrightness(animateValue, rampSpeed); } } diff --git a/services/core/xsd/display-device-config/display-device-config.xsd b/services/core/xsd/display-device-config/display-device-config.xsd index 1cb9e5786a703..7d705c1fac690 100644 --- a/services/core/xsd/display-device-config/display-device-config.xsd +++ b/services/core/xsd/display-device-config/display-device-config.xsd @@ -35,6 +35,18 @@ + + + + + + + + + + + + diff --git a/services/core/xsd/display-device-config/schema/current.txt b/services/core/xsd/display-device-config/schema/current.txt index e073ab3675caf..eb3f1b7519635 100644 --- a/services/core/xsd/display-device-config/schema/current.txt +++ b/services/core/xsd/display-device-config/schema/current.txt @@ -7,10 +7,18 @@ package com.android.server.display.config { method public com.android.server.display.config.DisplayQuirks getQuirks(); method @NonNull public final java.math.BigDecimal getScreenBrightnessDefault(); method @NonNull public final com.android.server.display.config.NitsMap getScreenBrightnessMap(); + method public final java.math.BigDecimal getScreenBrightnessRampFastDecrease(); + method public final java.math.BigDecimal getScreenBrightnessRampFastIncrease(); + method public final java.math.BigDecimal getScreenBrightnessRampSlowDecrease(); + method public final java.math.BigDecimal getScreenBrightnessRampSlowIncrease(); method public void setHighBrightnessMode(com.android.server.display.config.HighBrightnessMode); method public void setQuirks(com.android.server.display.config.DisplayQuirks); method public final void setScreenBrightnessDefault(@NonNull java.math.BigDecimal); method public final void setScreenBrightnessMap(@NonNull com.android.server.display.config.NitsMap); + method public final void setScreenBrightnessRampFastDecrease(java.math.BigDecimal); + method public final void setScreenBrightnessRampFastIncrease(java.math.BigDecimal); + method public final void setScreenBrightnessRampSlowDecrease(java.math.BigDecimal); + method public final void setScreenBrightnessRampSlowIncrease(java.math.BigDecimal); } public class DisplayQuirks {