Merge "Adjust float-to-int brightness conversion to be purely in float." into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
28e8a2c0ca
@@ -84,17 +84,17 @@ public class BrightnessSynchronizer{
|
|||||||
* Converts between the int brightness system and the float brightness system.
|
* Converts between the int brightness system and the float brightness system.
|
||||||
*/
|
*/
|
||||||
public static float brightnessIntToFloat(Context context, int brightnessInt) {
|
public static float brightnessIntToFloat(Context context, int brightnessInt) {
|
||||||
PowerManager pm = context.getSystemService(PowerManager.class);
|
final PowerManager pm = context.getSystemService(PowerManager.class);
|
||||||
float pmMinBrightness = pm.getBrightnessConstraint(
|
final float pmMinBrightness = pm.getBrightnessConstraint(
|
||||||
PowerManager.BRIGHTNESS_CONSTRAINT_TYPE_MINIMUM);
|
PowerManager.BRIGHTNESS_CONSTRAINT_TYPE_MINIMUM);
|
||||||
float pmMaxBrightness = pm.getBrightnessConstraint(
|
final float pmMaxBrightness = pm.getBrightnessConstraint(
|
||||||
PowerManager.BRIGHTNESS_CONSTRAINT_TYPE_MAXIMUM);
|
PowerManager.BRIGHTNESS_CONSTRAINT_TYPE_MAXIMUM);
|
||||||
int minBrightnessInt = brightnessFloatToInt(pmMinBrightness, PowerManager.BRIGHTNESS_MIN,
|
final int minBrightnessInt = Math.round(brightnessFloatToIntRange(pmMinBrightness,
|
||||||
PowerManager.BRIGHTNESS_MAX, PowerManager.BRIGHTNESS_OFF + 1,
|
PowerManager.BRIGHTNESS_MIN, PowerManager.BRIGHTNESS_MAX,
|
||||||
PowerManager.BRIGHTNESS_ON);
|
PowerManager.BRIGHTNESS_OFF + 1, PowerManager.BRIGHTNESS_ON));
|
||||||
int maxBrightnessInt = brightnessFloatToInt(pmMaxBrightness, PowerManager.BRIGHTNESS_MIN,
|
final int maxBrightnessInt = Math.round(brightnessFloatToIntRange(pmMaxBrightness,
|
||||||
PowerManager.BRIGHTNESS_MAX, PowerManager.BRIGHTNESS_OFF + 1,
|
PowerManager.BRIGHTNESS_MIN, PowerManager.BRIGHTNESS_MAX,
|
||||||
PowerManager.BRIGHTNESS_ON);
|
PowerManager.BRIGHTNESS_OFF + 1, PowerManager.BRIGHTNESS_ON));
|
||||||
|
|
||||||
return brightnessIntToFloat(brightnessInt, minBrightnessInt, maxBrightnessInt,
|
return brightnessIntToFloat(brightnessInt, minBrightnessInt, maxBrightnessInt,
|
||||||
pmMinBrightness, pmMaxBrightness);
|
pmMinBrightness, pmMaxBrightness);
|
||||||
@@ -119,34 +119,43 @@ public class BrightnessSynchronizer{
|
|||||||
* Converts between the float brightness system and the int brightness system.
|
* Converts between the float brightness system and the int brightness system.
|
||||||
*/
|
*/
|
||||||
public static int brightnessFloatToInt(Context context, float brightnessFloat) {
|
public static int brightnessFloatToInt(Context context, float brightnessFloat) {
|
||||||
PowerManager pm = context.getSystemService(PowerManager.class);
|
return Math.round(brightnessFloatToIntRange(context, brightnessFloat));
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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,
|
public static float brightnessFloatToIntRange(Context context, float brightnessFloat) {
|
||||||
int minInt, int maxInt) {
|
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)) {
|
if (floatEquals(brightnessFloat, PowerManager.BRIGHTNESS_OFF_FLOAT)) {
|
||||||
return PowerManager.BRIGHTNESS_OFF;
|
return PowerManager.BRIGHTNESS_OFF;
|
||||||
} else if (Float.isNaN(brightnessFloat)) {
|
} else if (Float.isNaN(brightnessFloat)) {
|
||||||
return PowerManager.BRIGHTNESS_INVALID;
|
return PowerManager.BRIGHTNESS_INVALID;
|
||||||
} else {
|
} else {
|
||||||
return Math.round(MathUtils.constrainedMap((float) minInt, (float) maxInt, minFloat,
|
return MathUtils.constrainedMap(minInt, maxInt, minFloat, maxFloat, brightnessFloat);
|
||||||
maxFloat, brightnessFloat));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -201,7 +201,6 @@ final class LocalDisplayAdapter extends DisplayAdapter {
|
|||||||
private SurfaceControl.DisplayConfig[] mDisplayConfigs;
|
private SurfaceControl.DisplayConfig[] mDisplayConfigs;
|
||||||
private Spline mSystemBrightnessToNits;
|
private Spline mSystemBrightnessToNits;
|
||||||
private Spline mNitsToHalBrightness;
|
private Spline mNitsToHalBrightness;
|
||||||
private boolean mHalBrightnessSupport;
|
|
||||||
|
|
||||||
private DisplayDeviceConfig mDisplayDeviceConfig;
|
private DisplayDeviceConfig mDisplayDeviceConfig;
|
||||||
|
|
||||||
@@ -225,7 +224,6 @@ final class LocalDisplayAdapter extends DisplayAdapter {
|
|||||||
}
|
}
|
||||||
mAllmSupported = SurfaceControl.getAutoLowLatencyModeSupport(displayToken);
|
mAllmSupported = SurfaceControl.getAutoLowLatencyModeSupport(displayToken);
|
||||||
mGameContentTypeSupported = SurfaceControl.getGameContentTypeSupport(displayToken);
|
mGameContentTypeSupported = SurfaceControl.getGameContentTypeSupport(displayToken);
|
||||||
mHalBrightnessSupport = SurfaceControl.getDisplayBrightnessSupport(displayToken);
|
|
||||||
mDisplayDeviceConfig = null;
|
mDisplayDeviceConfig = null;
|
||||||
// Defer configuration file loading
|
// Defer configuration file loading
|
||||||
BackgroundThread.getHandler().sendMessage(PooledLambda.obtainMessage(
|
BackgroundThread.getHandler().sendMessage(PooledLambda.obtainMessage(
|
||||||
@@ -717,11 +715,10 @@ final class LocalDisplayAdapter extends DisplayAdapter {
|
|||||||
Trace.traceBegin(Trace.TRACE_TAG_POWER, "setDisplayBrightness("
|
Trace.traceBegin(Trace.TRACE_TAG_POWER, "setDisplayBrightness("
|
||||||
+ "id=" + physicalDisplayId + ", brightness=" + brightness + ")");
|
+ "id=" + physicalDisplayId + ", brightness=" + brightness + ")");
|
||||||
try {
|
try {
|
||||||
// TODO: make it float
|
|
||||||
if (isHalBrightnessRangeSpecified()) {
|
if (isHalBrightnessRangeSpecified()) {
|
||||||
brightness = displayBrightnessToHalBrightness(
|
brightness = displayBrightnessToHalBrightness(
|
||||||
BrightnessSynchronizer.brightnessFloatToInt(getContext(),
|
BrightnessSynchronizer.brightnessFloatToIntRange(
|
||||||
brightness));
|
getContext(), brightness));
|
||||||
}
|
}
|
||||||
if (mBacklight != null) {
|
if (mBacklight != null) {
|
||||||
mBacklight.setBrightness(brightness);
|
mBacklight.setBrightness(brightness);
|
||||||
@@ -744,12 +741,13 @@ final class LocalDisplayAdapter extends DisplayAdapter {
|
|||||||
* Hal brightness space if the HAL brightness space has been provided via
|
* Hal brightness space if the HAL brightness space has been provided via
|
||||||
* a display device configuration file.
|
* a display device configuration file.
|
||||||
*/
|
*/
|
||||||
private float displayBrightnessToHalBrightness(int brightness) {
|
private float displayBrightnessToHalBrightness(float brightness) {
|
||||||
if (!isHalBrightnessRangeSpecified()) {
|
if (!isHalBrightnessRangeSpecified()) {
|
||||||
return PowerManager.BRIGHTNESS_INVALID_FLOAT;
|
return PowerManager.BRIGHTNESS_INVALID_FLOAT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (brightness == 0) {
|
if (BrightnessSynchronizer.floatEquals(
|
||||||
|
brightness, PowerManager.BRIGHTNESS_OFF)) {
|
||||||
return PowerManager.BRIGHTNESS_OFF_FLOAT;
|
return PowerManager.BRIGHTNESS_OFF_FLOAT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user