Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 486626b5 authored by Rupesh Bansal's avatar Rupesh Bansal Committed by Android (Google) Code Review
Browse files

Merge "Port lux and nit mappings from device config to display specific configs" into tm-qpr-dev

parents 28636f87 54a32f3d
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -1567,8 +1567,7 @@
    <bool name="config_enableIdleScreenBrightnessMode">false</bool>

    <!-- Array of desired screen brightness in nits corresponding to the lux values
         in the config_autoBrightnessLevels array. As with config_screenBrightnessMinimumNits and
         config_screenBrightnessMaximumNits, the display brightness is defined as the measured
         in the config_autoBrightnessLevels array. The display brightness is defined as the measured
         brightness of an all-white image.

         If this is defined then:
@@ -1589,7 +1588,7 @@
    <array name="config_autoBrightnessDisplayValuesNitsIdle">
    </array>

    <!-- Array of output values for button backlight corresponding to the luX values
    <!-- Array of output values for button backlight corresponding to the lux values
         in the config_autoBrightnessLevels array.  This array should have size one greater
         than the size of the config_autoBrightnessLevels array.
         The brightness values must be between 0 and 255 and be non-decreasing.
+2 −4
Original line number Diff line number Diff line
@@ -116,10 +116,8 @@ public abstract class BrightnessMappingStrategy {
            luxLevels = getLuxLevels(resources.getIntArray(
                    com.android.internal.R.array.config_autoBrightnessLevelsIdle));
        } else {
            brightnessLevelsNits = getFloatArray(resources.obtainTypedArray(
                    com.android.internal.R.array.config_autoBrightnessDisplayValuesNits));
            luxLevels = getLuxLevels(resources.getIntArray(
                    com.android.internal.R.array.config_autoBrightnessLevels));
            brightnessLevelsNits = displayDeviceConfig.getAutoBrightnessBrighteningLevelsNits();
            luxLevels = displayDeviceConfig.getAutoBrightnessBrighteningLevelsLux();
        }

        // Display independent, mode independent values
+117 −2
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.annotation.NonNull;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.hardware.display.DisplayManagerInternal;
import android.hardware.display.DisplayManagerInternal.RefreshRateLimitation;
import android.os.Environment;
@@ -155,6 +156,16 @@ import javax.xml.datatype.DatatypeConfigurationException;
 *          <darkeningLightDebounceMillis>
 *              1000
 *          </darkeningLightDebounceMillis>
 *          <displayBrightnessMapping>
 *              <displayBrightnessPoint>
 *                  <lux>50</lux>
 *                  <nits>45.32</nits>
 *              </displayBrightnessPoint>
 *              <displayBrightnessPoint>
 *                  <lux>80</lux>
 *                  <nits>75.43</nits>
 *              </displayBrightnessPoint>
 *          </displayBrightnessMapping>
 *      </autoBrightness>
 *
 *      <screenBrightnessRampFastDecrease>0.01</screenBrightnessRampFastDecrease>
@@ -268,6 +279,34 @@ public class DisplayDeviceConfig {
    // for the corresponding values above
    private float[] mBrightness;


    /**
     * Array of desired screen brightness in nits corresponding to the lux values
     * in the mBrightnessLevelsLux array. The display brightness is defined as the
     * measured brightness of an all-white image. The brightness values must be non-negative and
     * non-decreasing. This must be overridden in platform specific overlays
     */
    private float[] mBrightnessLevelsNits;

    /**
     * Array of light sensor lux values to define our levels for auto backlight
     * brightness support.

     * The N + 1 entries of this array define N control points defined in mBrightnessLevelsNits,
     * with first value always being 0 lux

     * The control points must be strictly increasing.  Each control point
     * corresponds to an entry in the brightness backlight values arrays.
     * For example, if lux == level[1] (second element of the levels array)
     * then the brightness will be determined by value[0] (first element
     * of the brightness values array).
     *
     * Spline interpolation is used to determine the auto-brightness
     * backlight values for lux levels between these control points.
     *
     */
    private float[] mBrightnessLevelsLux;

    private float mBacklightMinimum = Float.NaN;
    private float mBacklightMaximum = Float.NaN;
    private float mBrightnessDefault = Float.NaN;
@@ -661,6 +700,20 @@ public class DisplayDeviceConfig {
        return mAutoBrightnessBrighteningLightDebounce;
    }

    /**
     * @return Auto brightness brightening ambient lux levels
     */
    public float[] getAutoBrightnessBrighteningLevelsLux() {
        return mBrightnessLevelsLux;
    }

    /**
     * @return Auto brightness brightening nits levels
     */
    public float[] getAutoBrightnessBrighteningLevelsNits() {
        return mBrightnessLevelsNits;
    }

    @Override
    public String toString() {
        return "DisplayDeviceConfig{"
@@ -703,6 +756,8 @@ public class DisplayDeviceConfig {
                + mAutoBrightnessBrighteningLightDebounce
                + ", mAutoBrightnessDarkeningLightDebounce= "
                + mAutoBrightnessDarkeningLightDebounce
                + ", mBrightnessLevelsLux= " + Arrays.toString(mBrightnessLevelsLux)
                + ", mBrightnessLevelsNits= " + Arrays.toString(mBrightnessLevelsNits)
                + "}";
    }

@@ -779,6 +834,7 @@ public class DisplayDeviceConfig {
        loadBrightnessRampsFromConfigXml();
        loadAmbientLightSensorFromConfigXml();
        setProxSensorUnspecified();
        loadAutoBrightnessConfigsFromConfigXml();
        mLoadedFrom = "<config.xml>";
    }

@@ -991,6 +1047,7 @@ public class DisplayDeviceConfig {
    private void loadAutoBrightnessConfigValues(DisplayConfiguration config) {
        loadAutoBrightnessBrighteningLightDebounce(config.getAutoBrightness());
        loadAutoBrightnessDarkeningLightDebounce(config.getAutoBrightness());
        loadAutoBrightnessDisplayBrightnessMapping(config.getAutoBrightness());
    }

    /**
@@ -1023,6 +1080,35 @@ public class DisplayDeviceConfig {
        }
    }

    /**
     * Loads the auto-brightness display brightness mappings. Internally, this takes care of
     * loading the value from the display config, and if not present, falls back to config.xml.
     */
    private void loadAutoBrightnessDisplayBrightnessMapping(AutoBrightness autoBrightnessConfig) {
        if (autoBrightnessConfig == null
                || autoBrightnessConfig.getDisplayBrightnessMapping() == null) {
            mBrightnessLevelsNits = getFloatArray(mContext.getResources()
                    .obtainTypedArray(com.android.internal.R.array
                            .config_autoBrightnessDisplayValuesNits), PowerManager
                    .BRIGHTNESS_OFF_FLOAT);
            mBrightnessLevelsLux = getLuxLevels(mContext.getResources()
                    .getIntArray(com.android.internal.R.array
                            .config_autoBrightnessLevels));
        } else {
            final int size = autoBrightnessConfig.getDisplayBrightnessMapping()
                    .getDisplayBrightnessPoint().size();
            mBrightnessLevelsNits = new float[size];
            // The first control point is implicit and always at 0 lux.
            mBrightnessLevelsLux = new float[size + 1];
            for (int i = 0; i < size; i++) {
                mBrightnessLevelsNits[i] = autoBrightnessConfig.getDisplayBrightnessMapping()
                        .getDisplayBrightnessPoint().get(i).getNits().floatValue();
                mBrightnessLevelsLux[i + 1] = autoBrightnessConfig.getDisplayBrightnessMapping()
                        .getDisplayBrightnessPoint().get(i).getLux().floatValue();
            }
        }
    }

    private void loadBrightnessMapFromConfigXml() {
        // Use the config.xml mapping
        final Resources res = mContext.getResources();
@@ -1248,6 +1334,10 @@ public class DisplayDeviceConfig {
                com.android.internal.R.string.config_displayLightSensorType);
    }

    private void loadAutoBrightnessConfigsFromConfigXml() {
        loadAutoBrightnessDisplayBrightnessMapping(null /*AutoBrightnessConfig*/);
    }

    private void loadAmbientLightSensorFromDdc(DisplayConfiguration config) {
        final SensorDetails sensorDetails = config.getLightSensor();
        if (sensorDetails != null) {
@@ -1390,6 +1480,31 @@ public class DisplayDeviceConfig {
        }
    }

    /**
     * Extracts a float array from the specified {@link TypedArray}.
     *
     * @param array The array to convert.
     * @return the given array as a float array.
     */
    public static float[] getFloatArray(TypedArray array, float defaultValue) {
        final int n = array.length();
        float[] vals = new float[n];
        for (int i = 0; i < n; i++) {
            vals[i] = array.getFloat(i, defaultValue);
        }
        array.recycle();
        return vals;
    }

    private static float[] getLuxLevels(int[] lux) {
        // The first control point is implicit and always at 0 lux.
        float[] levels = new float[lux.length + 1];
        for (int i = 0; i < lux.length; i++) {
            levels[i + 1] = (float) lux[i];
        }
        return levels;
    }

    static class SensorData {
        public String type;
        public String name;
+0 −33
Original line number Diff line number Diff line
<!--
    Copyright (C) 2022 The Android Open Source Project

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->
<xs:schema version="2.0"
           elementFormDefault="qualified"
           xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:complexType name="autoBrightness">
        <xs:sequence>
            <!-- Sets the debounce for autoBrightness brightening in millis-->
            <xs:element name="brighteningLightDebounceMillis" type="xs:nonNegativeInteger"
                        minOccurs="0" maxOccurs="1">
                <xs:annotation name="final"/>
            </xs:element>
            <!-- Sets the debounce for autoBrightness darkening in millis-->
            <xs:element name="darkeningLightDebounceMillis" type="xs:nonNegativeInteger"
                        minOccurs="0" maxOccurs="1">
                <xs:annotation name="final"/>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:schema>
 No newline at end of file
+70 −1
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@
<xs:schema version="2.0"
           elementFormDefault="qualified"
           xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:include schemaLocation="autobrightness.xsd" />
    <xs:element name="displayConfiguration">
        <xs:complexType>
            <xs:sequence>
@@ -343,4 +342,74 @@
            <xs:annotation name="final"/>
        </xs:element>
    </xs:complexType>

    <xs:complexType name="autoBrightness">
        <xs:sequence>
            <!-- Sets the debounce for autoBrightness brightening in millis-->
            <xs:element name="brighteningLightDebounceMillis" type="xs:nonNegativeInteger"
                        minOccurs="0" maxOccurs="1">
                <xs:annotation name="final"/>
            </xs:element>
            <!-- Sets the debounce for autoBrightness darkening in millis-->
            <xs:element name="darkeningLightDebounceMillis" type="xs:nonNegativeInteger"
                        minOccurs="0" maxOccurs="1">
                <xs:annotation name="final"/>
            </xs:element>
            <!-- Sets the brightness mapping of the desired screen brightness in nits to the
             corresponding lux for the current display -->
            <xs:element name="displayBrightnessMapping" type="displayBrightnessMapping"
                        minOccurs="0" maxOccurs="1">
                <xs:annotation name="final"/>
            </xs:element>
        </xs:sequence>
    </xs:complexType>

    <!-- Represents the brightness mapping of the desired screen brightness in nits to the
             corresponding lux for the current display -->
    <xs:complexType name="displayBrightnessMapping">
        <xs:sequence>
            <!-- Sets the list of display brightness points, each representing the desired screen
            brightness in nits to the corresponding lux for the current display

            The N entries of this array define N + 1 control points as follows:
            (1-based arrays)

            Point 1:            (0, nits[1]):             currentLux <= 0
            Point 2:     (lux[1], nits[2]):       0 < currentLux <= lux[1]
            Point 3:     (lux[2], nits[3]):  lux[2] < currentLux <= lux[3]
            ...
            Point N+1: (lux[N], nits[N+1]):            lux[N] < currentLux

            The control points must be strictly increasing. Each control point
            corresponds to an entry in the brightness backlight values arrays.
            For example, if currentLux == lux[1] (first element of the levels array)
            then the brightness will be determined by nits[2] (second element
            of the brightness values array).
            -->
            <xs:element name="displayBrightnessPoint" type="displayBrightnessPoint"
                        minOccurs="1" maxOccurs="unbounded">
                <xs:annotation name="final"/>
            </xs:element>
        </xs:sequence>
    </xs:complexType>

    <!-- Represents a point in the display brightness mapping, representing the lux level from the
    light sensor to the desired screen brightness in nits at this level  -->
    <xs:complexType name="displayBrightnessPoint">
        <xs:sequence>
            <!-- The lux level from the light sensor. This must be a non-negative integer -->
            <xs:element name="lux" type="xs:nonNegativeInteger"
                        minOccurs="1" maxOccurs="1">
                <xs:annotation name="final"/>
            </xs:element>

            <!-- Desired screen brightness in nits corresponding to the suggested lux values.
             The display brightness is defined as the measured brightness of an all-white image.
             This must be a non-negative integer -->
            <xs:element name="nits" type="nonNegativeDecimal"
                        minOccurs="1" maxOccurs="1">
                <xs:annotation name="final"/>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:schema>
Loading