Merge "Adjust float-to-int brightness conversion to be purely in float." into rvc-dev am: 28e8a2c0ca am: 5c46e05058

Change-Id: If70f695dd7d42bd23ca70c6ebde2e4a98628c46f
This commit is contained in:
TreeHugger Robot
2020-05-18 13:18:28 +00:00
committed by Automerger Merge Worker
2 changed files with 42 additions and 35 deletions

View File

@@ -84,17 +84,17 @@ public class BrightnessSynchronizer{
* Converts between the int brightness system and the float brightness system.
*/
public static float brightnessIntToFloat(Context context, int brightnessInt) {
PowerManager pm = context.getSystemService(PowerManager.class);
float pmMinBrightness = pm.getBrightnessConstraint(
final PowerManager pm = context.getSystemService(PowerManager.class);
final float pmMinBrightness = pm.getBrightnessConstraint(
PowerManager.BRIGHTNESS_CONSTRAINT_TYPE_MINIMUM);
float pmMaxBrightness = pm.getBrightnessConstraint(
final float pmMaxBrightness = pm.getBrightnessConstraint(
PowerManager.BRIGHTNESS_CONSTRAINT_TYPE_MAXIMUM);
int minBrightnessInt = brightnessFloatToInt(pmMinBrightness, PowerManager.BRIGHTNESS_MIN,
PowerManager.BRIGHTNESS_MAX, PowerManager.BRIGHTNESS_OFF + 1,
PowerManager.BRIGHTNESS_ON);
int maxBrightnessInt = brightnessFloatToInt(pmMaxBrightness, PowerManager.BRIGHTNESS_MIN,
PowerManager.BRIGHTNESS_MAX, PowerManager.BRIGHTNESS_OFF + 1,
PowerManager.BRIGHTNESS_ON);
final int minBrightnessInt = Math.round(brightnessFloatToIntRange(pmMinBrightness,
PowerManager.BRIGHTNESS_MIN, PowerManager.BRIGHTNESS_MAX,
PowerManager.BRIGHTNESS_OFF + 1, PowerManager.BRIGHTNESS_ON));
final int maxBrightnessInt = Math.round(brightnessFloatToIntRange(pmMaxBrightness,
PowerManager.BRIGHTNESS_MIN, PowerManager.BRIGHTNESS_MAX,
PowerManager.BRIGHTNESS_OFF + 1, PowerManager.BRIGHTNESS_ON));
return brightnessIntToFloat(brightnessInt, minBrightnessInt, maxBrightnessInt,
pmMinBrightness, pmMaxBrightness);
@@ -119,34 +119,43 @@ public class BrightnessSynchronizer{
* Converts between the float brightness system and the int brightness system.
*/
public static int brightnessFloatToInt(Context context, float brightnessFloat) {
PowerManager pm = context.getSystemService(PowerManager.class);
float pmMinBrightness = pm.getBrightnessConstraint(
PowerManager.BRIGHTNESS_CONSTRAINT_TYPE_MINIMUM);
float pmMaxBrightness = pm.getBrightnessConstraint(
PowerManager.BRIGHTNESS_CONSTRAINT_TYPE_MAXIMUM);
int minBrightnessInt = brightnessFloatToInt(pmMinBrightness, PowerManager.BRIGHTNESS_MIN,
PowerManager.BRIGHTNESS_MAX, PowerManager.BRIGHTNESS_OFF + 1,
PowerManager.BRIGHTNESS_ON);
int maxBrightnessInt = brightnessFloatToInt(pmMaxBrightness, PowerManager.BRIGHTNESS_MIN,
PowerManager.BRIGHTNESS_MAX, PowerManager.BRIGHTNESS_OFF + 1,
PowerManager.BRIGHTNESS_ON);
return brightnessFloatToInt(brightnessFloat, pmMinBrightness, pmMaxBrightness,
minBrightnessInt, maxBrightnessInt);
return Math.round(brightnessFloatToIntRange(context, brightnessFloat));
}
/**
* Converts between the float brightness system and the int brightness system.
* Converts between the float brightness system and the int brightness system, but returns
* the converted value as a float within the int-system's range. This method helps with
* conversions from one system to the other without losing the floating-point precision.
*/
public static int brightnessFloatToInt(float brightnessFloat, float minFloat, float maxFloat,
int minInt, int maxInt) {
public static float brightnessFloatToIntRange(Context context, float brightnessFloat) {
final PowerManager pm = context.getSystemService(PowerManager.class);
final float minFloat = pm.getBrightnessConstraint(
PowerManager.BRIGHTNESS_CONSTRAINT_TYPE_MINIMUM);
final float maxFloat = pm.getBrightnessConstraint(
PowerManager.BRIGHTNESS_CONSTRAINT_TYPE_MAXIMUM);
final float minInt = brightnessFloatToIntRange(minFloat,
PowerManager.BRIGHTNESS_MIN, PowerManager.BRIGHTNESS_MAX,
PowerManager.BRIGHTNESS_OFF + 1, PowerManager.BRIGHTNESS_ON);
final float maxInt = brightnessFloatToIntRange(maxFloat,
PowerManager.BRIGHTNESS_MIN, PowerManager.BRIGHTNESS_MAX,
PowerManager.BRIGHTNESS_OFF + 1, PowerManager.BRIGHTNESS_ON);
return brightnessFloatToIntRange(brightnessFloat, minFloat, maxFloat, minInt, maxInt);
}
/**
* Translates specified value from the float brightness system to the int brightness system,
* given the min/max of each range. Accounts for special values such as OFF and invalid values.
* Value returned as a float privimite (to preserve precision), but is a value within the
* int-system range.
*/
private static float brightnessFloatToIntRange(float brightnessFloat, float minFloat,
float maxFloat, float minInt, float maxInt) {
if (floatEquals(brightnessFloat, PowerManager.BRIGHTNESS_OFF_FLOAT)) {
return PowerManager.BRIGHTNESS_OFF;
} else if (Float.isNaN(brightnessFloat)) {
return PowerManager.BRIGHTNESS_INVALID;
} else {
return Math.round(MathUtils.constrainedMap((float) minInt, (float) maxInt, minFloat,
maxFloat, brightnessFloat));
return MathUtils.constrainedMap(minInt, maxInt, minFloat, maxFloat, brightnessFloat);
}
}

View File

@@ -201,7 +201,6 @@ final class LocalDisplayAdapter extends DisplayAdapter {
private SurfaceControl.DisplayConfig[] mDisplayConfigs;
private Spline mSystemBrightnessToNits;
private Spline mNitsToHalBrightness;
private boolean mHalBrightnessSupport;
private DisplayDeviceConfig mDisplayDeviceConfig;
@@ -225,7 +224,6 @@ final class LocalDisplayAdapter extends DisplayAdapter {
}
mAllmSupported = SurfaceControl.getAutoLowLatencyModeSupport(displayToken);
mGameContentTypeSupported = SurfaceControl.getGameContentTypeSupport(displayToken);
mHalBrightnessSupport = SurfaceControl.getDisplayBrightnessSupport(displayToken);
mDisplayDeviceConfig = null;
// Defer configuration file loading
BackgroundThread.getHandler().sendMessage(PooledLambda.obtainMessage(
@@ -717,11 +715,10 @@ final class LocalDisplayAdapter extends DisplayAdapter {
Trace.traceBegin(Trace.TRACE_TAG_POWER, "setDisplayBrightness("
+ "id=" + physicalDisplayId + ", brightness=" + brightness + ")");
try {
// TODO: make it float
if (isHalBrightnessRangeSpecified()) {
brightness = displayBrightnessToHalBrightness(
BrightnessSynchronizer.brightnessFloatToInt(getContext(),
brightness));
BrightnessSynchronizer.brightnessFloatToIntRange(
getContext(), brightness));
}
if (mBacklight != null) {
mBacklight.setBrightness(brightness);
@@ -744,12 +741,13 @@ final class LocalDisplayAdapter extends DisplayAdapter {
* Hal brightness space if the HAL brightness space has been provided via
* a display device configuration file.
*/
private float displayBrightnessToHalBrightness(int brightness) {
private float displayBrightnessToHalBrightness(float brightness) {
if (!isHalBrightnessRangeSpecified()) {
return PowerManager.BRIGHTNESS_INVALID_FLOAT;
}
if (brightness == 0) {
if (BrightnessSynchronizer.floatEquals(
brightness, PowerManager.BRIGHTNESS_OFF)) {
return PowerManager.BRIGHTNESS_OFF_FLOAT;
}