Merge "Stop RBC affecting brightness so drastically" into sc-qpr1-dev

This commit is contained in:
Fiona Campbell
2021-10-07 16:28:57 +00:00
committed by Android (Google) Code Review

View File

@@ -125,6 +125,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
private static final int MSG_IGNORE_PROXIMITY = 8;
private static final int MSG_STOP = 9;
private static final int MSG_UPDATE_BRIGHTNESS = 10;
private static final int MSG_UPDATE_RBC = 11;
private static final int PROXIMITY_UNKNOWN = -1;
private static final int PROXIMITY_NEGATIVE = 0;
@@ -422,13 +423,13 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
// PowerManager.BRIGHTNESS_INVALID_FLOAT when there's no temporary adjustment set.
private float mTemporaryAutoBrightnessAdjustment;
// Whether a reduce bright colors (rbc) change has been initiated by the user. We want to
// retain the current backlight level when rbc is toggled, since rbc additionally makes the
// screen appear dimmer using screen colors rather than backlight levels, and therefore we
// don't actually want to compensate for this by then in/decreasing the backlight when
// toggling this feature.
// Whether reduce bright colors (rbc) has been turned on, or a change in strength has been
// requested. We want to retain the current backlight level when rbc is toggled, since rbc
// additionally makes the screen appear dimmer using screen colors rather than backlight levels,
// and therefore we don't actually want to compensate for this by then in/decreasing the
// backlight when toggling this feature.
// This should be false during system start up.
private boolean mPendingUserRbcChange;
private boolean mPendingRbcOnOrChanged = false;
// Animators.
private ObjectAnimator mColorFadeOnAnimator;
@@ -564,23 +565,35 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
@Override
public void onReduceBrightColorsActivationChanged(boolean activated,
boolean userInitiated) {
applyReduceBrightColorsSplineAdjustment(userInitiated);
applyReduceBrightColorsSplineAdjustment(
/* rbcStrengthChanged= */ false, activated);
}
@Override
public void onReduceBrightColorsStrengthChanged(int strength) {
applyReduceBrightColorsSplineAdjustment(/*userInitiated*/ false);
applyReduceBrightColorsSplineAdjustment(
/* rbcStrengthChanged= */ true, /* justActivated= */ false);
}
});
if (active) {
applyReduceBrightColorsSplineAdjustment(/*userInitiated*/ false);
applyReduceBrightColorsSplineAdjustment(
/* rbcStrengthChanged= */ false, /* justActivated= */ false);
}
} else {
mCdsi = null;
}
}
private void applyReduceBrightColorsSplineAdjustment(boolean userInitiated) {
private void applyReduceBrightColorsSplineAdjustment(
boolean rbcStrengthChanged, boolean justActivated) {
final int strengthChanged = rbcStrengthChanged ? 1 : 0;
final int activated = justActivated ? 1 : 0;
mHandler.obtainMessage(MSG_UPDATE_RBC, strengthChanged, activated).sendToTarget();
sendUpdatePowerState();
}
private void handleRbcChanged(boolean strengthChanged, boolean justActivated) {
if (mBrightnessMapper == null) {
Log.w(TAG, "No brightness mapping available to recalculate splines");
return;
@@ -591,8 +604,13 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
adjustedNits[i] = mCdsi.getReduceBrightColorsAdjustedBrightnessNits(mNitsRange[i]);
}
mBrightnessMapper.recalculateSplines(mCdsi.isReduceBrightColorsActivated(), adjustedNits);
mPendingUserRbcChange = userInitiated;
sendUpdatePowerState();
mPendingRbcOnOrChanged = strengthChanged || justActivated;
// Reset model if strength changed OR rbc is turned off
if (strengthChanged || !justActivated && mAutomaticBrightnessController != null) {
mAutomaticBrightnessController.resetShortTermModel();
}
}
/**
@@ -926,7 +944,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
private void reloadReduceBrightColours() {
if (mCdsi != null && mCdsi.isReduceBrightColorsActivated()) {
applyReduceBrightColorsSplineAdjustment(/*userInitiated*/ false);
applyReduceBrightColorsSplineAdjustment(
/* rbcStrengthChanged= */ false, /* justActivated= */ false);
}
}
@@ -2072,21 +2091,24 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
return true;
}
// We want to return true if the user has set the screen brightness.
// If they have just turned RBC on (and therefore added that interaction to the curve),
// or changed the brightness another way, then we should return true.
private boolean updateUserSetScreenBrightness() {
final boolean brightnessSplineChanged = mPendingUserRbcChange;
if (mPendingUserRbcChange && !Float.isNaN(mCurrentScreenBrightnessSetting)) {
final boolean treatAsIfUserChanged = mPendingRbcOnOrChanged;
if (treatAsIfUserChanged && !Float.isNaN(mCurrentScreenBrightnessSetting)) {
mLastUserSetScreenBrightness = mCurrentScreenBrightnessSetting;
}
mPendingUserRbcChange = false;
mPendingRbcOnOrChanged = false;
if ((Float.isNaN(mPendingScreenBrightnessSetting)
|| mPendingScreenBrightnessSetting < 0.0f)) {
return brightnessSplineChanged;
return treatAsIfUserChanged;
}
if (mCurrentScreenBrightnessSetting == mPendingScreenBrightnessSetting) {
mPendingScreenBrightnessSetting = PowerManager.BRIGHTNESS_INVALID_FLOAT;
mTemporaryScreenBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT;
return brightnessSplineChanged;
return treatAsIfUserChanged;
}
setCurrentScreenBrightness(mPendingScreenBrightnessSetting);
mLastUserSetScreenBrightness = mPendingScreenBrightnessSetting;
@@ -2428,6 +2450,12 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
}
handleSettingsChange(false /*userSwitch*/);
break;
case MSG_UPDATE_RBC:
final int strengthChanged = msg.arg1;
final int justActivated = msg.arg2;
handleRbcChanged(strengthChanged == 1, justActivated == 1);
break;
}
}
}