Compute DWB compensation for luminance drop
Bug: 214402192 Test: atest FrameworksServicesTests:AmbientLuxTest Change-Id: Id61d6521d68f75d45d20b3a9ea3d1fba89410e05
This commit is contained in:
@@ -1453,7 +1453,7 @@ public final class ColorDisplayService extends SystemService {
|
||||
/**
|
||||
* Local service that allows color transforms to be enabled from other system services.
|
||||
*/
|
||||
public final class ColorDisplayServiceInternal {
|
||||
public class ColorDisplayServiceInternal {
|
||||
|
||||
/**
|
||||
* Set the current CCT value for the display white balance transform, and if the transform
|
||||
@@ -1472,6 +1472,11 @@ public final class ColorDisplayService extends SystemService {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Get the luminance of the current chromatic adaptation matrix. */
|
||||
public float getDisplayWhiteBalanceLuminance() {
|
||||
return mDisplayWhiteBalanceTintController.getLuminance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the CCT value for the display white balance transform to its default value.
|
||||
*/
|
||||
|
||||
@@ -251,6 +251,18 @@ final class DisplayWhiteBalanceTintController extends TintController {
|
||||
}
|
||||
}
|
||||
|
||||
public float getLuminance() {
|
||||
synchronized (mLock) {
|
||||
if (mChromaticAdaptationMatrix != null && mChromaticAdaptationMatrix.length == 9) {
|
||||
// Compute only the luminance (y) value of the xyz * [1 1 1] transform.
|
||||
return 1 / (mChromaticAdaptationMatrix[1] + mChromaticAdaptationMatrix[4]
|
||||
+ mChromaticAdaptationMatrix[7]);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ColorSpace.Rgb makeRgbColorSpaceFromXYZ(float[] redGreenBlueXYZ, float[] whiteXYZ) {
|
||||
return new ColorSpace.Rgb(
|
||||
"Display Color Space",
|
||||
|
||||
@@ -21,7 +21,6 @@ import android.util.Slog;
|
||||
import android.util.Spline;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.util.Preconditions;
|
||||
import com.android.server.LocalServices;
|
||||
import com.android.server.display.color.ColorDisplayService.ColorDisplayServiceInternal;
|
||||
import com.android.server.display.utils.AmbientFilter;
|
||||
@@ -455,6 +454,22 @@ public class DisplayWhiteBalanceController implements
|
||||
mLastAmbientColorTemperature = mAmbientColorTemperature;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the adjusted brightness, in nits, due to the DWB color adaptation
|
||||
*
|
||||
* @param requestedBrightnessNits brightness the framework requires to be output
|
||||
* @return the adjusted brightness the framework needs to output to counter the drop in
|
||||
* brightness due to DWB, or the requestedBrightnessNits if an adjustment cannot be made
|
||||
*/
|
||||
public float calculateAdjustedBrightnessNits(float requestedBrightnessNits) {
|
||||
float luminance = mColorDisplayServiceInternal.getDisplayWhiteBalanceLuminance();
|
||||
if (luminance == -1) {
|
||||
return requestedBrightnessNits;
|
||||
}
|
||||
float effectiveBrightness = requestedBrightnessNits * luminance;
|
||||
return (requestedBrightnessNits - effectiveBrightness) + requestedBrightnessNits;
|
||||
}
|
||||
|
||||
/**
|
||||
* The DisplayWhiteBalanceController decouples itself from its parent (DisplayPowerController)
|
||||
* by providing this interface to implement (and a method to set its callbacks object), and
|
||||
|
||||
@@ -21,6 +21,7 @@ import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyLong;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -37,7 +38,9 @@ import android.util.TypedValue;
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
|
||||
import com.android.internal.R;
|
||||
import com.android.server.LocalServices;
|
||||
import com.android.server.display.TestUtils;
|
||||
import com.android.server.display.color.ColorDisplayService;
|
||||
import com.android.server.display.utils.AmbientFilter;
|
||||
import com.android.server.display.utils.AmbientFilterStubber;
|
||||
|
||||
@@ -75,6 +78,7 @@ public final class AmbientLuxTest {
|
||||
@Mock private TypedArray mHighLightBiases;
|
||||
@Mock private TypedArray mAmbientColorTemperatures;
|
||||
@Mock private TypedArray mDisplayColorTemperatures;
|
||||
@Mock private ColorDisplayService.ColorDisplayServiceInternal mColorDisplayServiceInternalMock;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@@ -120,6 +124,18 @@ public final class AmbientLuxTest {
|
||||
R.array.config_displayWhiteBalanceHighLightAmbientBiases))
|
||||
.thenReturn(mHighLightBiases);
|
||||
mockThrottler();
|
||||
LocalServices.removeServiceForTest(ColorDisplayService.ColorDisplayServiceInternal.class);
|
||||
LocalServices.addService(ColorDisplayService.ColorDisplayServiceInternal.class,
|
||||
mColorDisplayServiceInternalMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCalculateAdjustedBrightnessNits() {
|
||||
doReturn(0.9f).when(mColorDisplayServiceInternalMock).getDisplayWhiteBalanceLuminance();
|
||||
DisplayWhiteBalanceController controller =
|
||||
DisplayWhiteBalanceFactory.create(mHandler, mSensorManagerMock, mResourcesSpy);
|
||||
final float adjustedNits = controller.calculateAdjustedBrightnessNits(500f);
|
||||
assertEquals(/* expected= */ 550f, adjustedNits, /* delta= */ 0.001);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user