From 8063e59a9a5455bc0dfb7b716f6fa24cf4127045 Mon Sep 17 00:00:00 2001 From: Danny Baumann Date: Wed, 1 Apr 2015 08:44:37 +0200 Subject: [PATCH] Increase brightness faster if ambient light is brightening quickly. The point of doing this is when going from indoors to bright sunlight, the brightness adjustment currently leaves one with looking at an unreadable display for a couple of seconds. Increase responsiveness in that scenario to ramp up brightness faster. Change-Id: Idf8ca8ebcdcea06746b0c4f3ab94d2ddddafb32e --- core/res/res/values/cm_symbols.xml | 4 +++ core/res/res/values/config.xml | 1 + .../display/AutomaticBrightnessController.java | 29 ++++++++++++++++------ .../server/display/DisplayPowerController.java | 6 +++-- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/core/res/res/values/cm_symbols.xml b/core/res/res/values/cm_symbols.xml index 48d83e3fa918..47644a6bfbe9 100644 --- a/core/res/res/values/cm_symbols.xml +++ b/core/res/res/values/cm_symbols.xml @@ -68,4 +68,8 @@ + + + + diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index c00182efe100..1f5faf4f389b 100755 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -1090,6 +1090,7 @@ when adapting to brighter or darker environments. This parameter controls how quickly brightness changes occur in response to an observed change in light level that exceeds the hysteresis threshold. --> + 500 4000 8000 diff --git a/services/core/java/com/android/server/display/AutomaticBrightnessController.java b/services/core/java/com/android/server/display/AutomaticBrightnessController.java index c16dac23d4c7..94df50f409be 100644 --- a/services/core/java/com/android/server/display/AutomaticBrightnessController.java +++ b/services/core/java/com/android/server/display/AutomaticBrightnessController.java @@ -55,6 +55,11 @@ class AutomaticBrightnessController { private static final float BRIGHTENING_LIGHT_HYSTERESIS = 0.10f; private static final float DARKENING_LIGHT_HYSTERESIS = 0.20f; + // Threshold (in lux) to select between normal and fast debounce time. + // If the difference between last sample and weighted value is larger than this value, + // fast debounce is used. + private static final float BRIGHTENING_FAST_THRESHOLD = 1000f; + // How long the current sensor reading is assumed to be valid beyond the current time. // This provides a bit of prediction, as well as ensures that the weight for the last sample is // non-zero, which in turn ensures that the total weight is non-zero. @@ -99,6 +104,7 @@ class AutomaticBrightnessController { // when adapting to brighter or darker environments. This parameter controls how quickly // brightness changes occur in response to an observed change in light level that exceeds the // hysteresis threshold. + private final long mBrighteningLightFastDebounceConfig; private final long mBrighteningLightDebounceConfig; private final long mDarkeningLightDebounceConfig; @@ -188,6 +194,7 @@ class AutomaticBrightnessController { SensorManager sensorManager, Spline autoBrightnessSpline, int lightSensorWarmUpTime, int brightnessMin, int brightnessMax, float dozeScaleFactor, int lightSensorRate, long brighteningLightDebounceConfig, + long brighteningLightFastDebounceConfig, long darkeningLightDebounceConfig, boolean resetAmbientLuxAfterWarmUpConfig, int ambientLightHorizon, float autoBrightnessAdjustmentMaxGamma ) { mCallbacks = callbacks; @@ -200,6 +207,7 @@ class AutomaticBrightnessController { mDozeScaleFactor = dozeScaleFactor; mLightSensorRate = lightSensorRate; mBrighteningLightDebounceConfig = brighteningLightDebounceConfig; + mBrighteningLightFastDebounceConfig = brighteningLightFastDebounceConfig; mDarkeningLightDebounceConfig = darkeningLightDebounceConfig; mResetAmbientLuxAfterWarmUpConfig = resetAmbientLuxAfterWarmUpConfig; mAmbientLightHorizon = ambientLightHorizon; @@ -262,6 +270,7 @@ class AutomaticBrightnessController { pw.println(" mScreenBrightnessRangeMaximum=" + mScreenBrightnessRangeMaximum); pw.println(" mLightSensorWarmUpTimeConfig=" + mLightSensorWarmUpTimeConfig); pw.println(" mBrighteningLightDebounceConfig=" + mBrighteningLightDebounceConfig); + pw.println(" mBrighteningLightFastDebounceConfig=" + mBrighteningLightFastDebounceConfig); pw.println(" mDarkeningLightDebounceConfig=" + mDarkeningLightDebounceConfig); pw.println(" mResetAmbientLuxAfterWarmUpConfig=" + mResetAmbientLuxAfterWarmUpConfig); @@ -314,6 +323,7 @@ class AutomaticBrightnessController { private void handleLightSensorEvent(long time, float lux) { mHandler.removeMessages(MSG_UPDATE_AMBIENT_LUX); + if (DEBUG) Slog.d(TAG, "handleLightSensorEvent: time=" + time + ", lux=" + lux); applyLightSensorMeasurement(time, lux); updateAmbientLux(time); } @@ -386,7 +396,7 @@ class AutomaticBrightnessController { return x * (x * 0.5f + mWeightingIntercept); } - private long nextAmbientLightBrighteningTransition(long time) { + private long nextAmbientLightBrighteningTransition(long time, float ambientLux) { final int N = mAmbientLightRingBuffer.size(); long earliestValidTime = time; for (int i = N - 1; i >= 0; i--) { @@ -395,10 +405,13 @@ class AutomaticBrightnessController { } earliestValidTime = mAmbientLightRingBuffer.getTime(i); } - return earliestValidTime + mBrighteningLightDebounceConfig; + + long debounceDelay = mLastObservedLux - ambientLux > BRIGHTENING_FAST_THRESHOLD + ? mBrighteningLightFastDebounceConfig : mBrighteningLightDebounceConfig; + return earliestValidTime + debounceDelay; } - private long nextAmbientLightDarkeningTransition(long time) { + private long nextAmbientLightDarkeningTransition(long time, float ambientLux) { final int N = mAmbientLightRingBuffer.size(); long earliestValidTime = time; for (int i = N - 1; i >= 0; i--) { @@ -442,13 +455,12 @@ class AutomaticBrightnessController { updateAutoBrightness(true); } - long nextBrightenTransition = nextAmbientLightBrighteningTransition(time); - long nextDarkenTransition = nextAmbientLightDarkeningTransition(time); float ambientLux = calculateAmbientLux(time); + long nextBrightenTransition = nextAmbientLightBrighteningTransition(time, ambientLux); + long nextDarkenTransition = nextAmbientLightDarkeningTransition(time, ambientLux); if (ambientLux >= mBrighteningLuxThreshold && nextBrightenTransition <= time || ambientLux <= mDarkeningLuxThreshold && nextDarkenTransition <= time) { - setAmbientLux(ambientLux); if (DEBUG) { Slog.d(TAG, "updateAmbientLux: " + ((ambientLux > mAmbientLux) ? "Brightened" : "Darkened") + ": " @@ -456,9 +468,10 @@ class AutomaticBrightnessController { + ", mAmbientLightRingBuffer=" + mAmbientLightRingBuffer + ", mAmbientLux=" + mAmbientLux); } + setAmbientLux(ambientLux); updateAutoBrightness(true); - nextBrightenTransition = nextAmbientLightBrighteningTransition(time); - nextDarkenTransition = nextAmbientLightDarkeningTransition(time); + nextBrightenTransition = nextAmbientLightBrighteningTransition(time, ambientLux); + nextDarkenTransition = nextAmbientLightDarkeningTransition(time, ambientLux); } long nextTransitionTime = Math.min(nextDarkenTransition, nextBrightenTransition); // If one of the transitions is ready to occur, but the total weighted ambient lux doesn't diff --git a/services/core/java/com/android/server/display/DisplayPowerController.java b/services/core/java/com/android/server/display/DisplayPowerController.java index 7922dfbdddfc..944b5772b430 100644 --- a/services/core/java/com/android/server/display/DisplayPowerController.java +++ b/services/core/java/com/android/server/display/DisplayPowerController.java @@ -317,6 +317,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call com.android.internal.R.integer.config_autoBrightnessLightSensorRate); long brighteningLightDebounce = resources.getInteger( com.android.internal.R.integer.config_autoBrightnessBrighteningLightDebounce); + long brighteningLightFastDebounce = resources.getInteger( + com.android.internal.R.integer.config_autoBrightnessBrighteningLightFastDebounce); long darkeningLightDebounce = resources.getInteger( com.android.internal.R.integer.config_autoBrightnessDarkeningLightDebounce); boolean autoBrightnessResetAmbientLuxAfterWarmUp = resources.getBoolean( @@ -362,8 +364,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call handler.getLooper(), sensorManager, screenAutoBrightnessSpline, lightSensorWarmUpTimeConfig, screenBrightnessRangeMinimum, mScreenBrightnessRangeMaximum, dozeScaleFactor, lightSensorRate, - brighteningLightDebounce, darkeningLightDebounce, - autoBrightnessResetAmbientLuxAfterWarmUp, + brighteningLightDebounce, brighteningLightFastDebounce, + darkeningLightDebounce, autoBrightnessResetAmbientLuxAfterWarmUp, ambientLightHorizon, autoBrightnessAdjustmentMaxGamma); } } -- 2.11.0