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

Commit a95c39d6 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add brightness throttling map for concurrent displays"

parents 0401d48b 27403ad4
Loading
Loading
Loading
Loading
+65 −5
Original line number Diff line number Diff line
@@ -132,6 +132,16 @@ import javax.xml.datatype.DatatypeConfigurationException;
 *            <brightness>0.01</brightness>
 *          </brightnessThrottlingPoint>
 *        </brightnessThrottlingMap>
 *        <concurrentDisplaysBrightnessThrottlingMap>
 *          <brightnessThrottlingPoint>
 *            <thermalStatus>severe</thermalStatus>
 *            <brightness>0.07</brightness>
 *          </brightnessThrottlingPoint>
 *          <brightnessThrottlingPoint>
 *            <thermalStatus>critical</thermalStatus>
 *            <brightness>0.005</brightness>
 *          </brightnessThrottlingPoint>
 *        </concurrentDisplaysBrightnessThrottlingMap>
 *      </thermalThrottling>
 *
 *      <refreshRate>
@@ -613,6 +623,8 @@ public class DisplayDeviceConfig {
    // overwritten value.
    private BrightnessThrottlingData mBrightnessThrottlingData;
    private BrightnessThrottlingData mOriginalBrightnessThrottlingData;
    // The concurrent displays mode might need a stricter throttling policy
    private BrightnessThrottlingData mConcurrentDisplaysBrightnessThrottlingData;

    @VisibleForTesting
    DisplayDeviceConfig(Context context) {
@@ -1258,12 +1270,20 @@ public class DisplayDeviceConfig {
    }

    /**
     * @return brightness throttling data configuration data for the display.
     * @return brightness throttling configuration data for the display.
     */
    public BrightnessThrottlingData getBrightnessThrottlingData() {
        return BrightnessThrottlingData.create(mBrightnessThrottlingData);
    }

    /**
     * @return brightness throttling configuration data for the display for the concurrent
     * displays mode.
     */
    public BrightnessThrottlingData getConcurrentDisplaysBrightnessThrottlingData() {
        return BrightnessThrottlingData.create(mConcurrentDisplaysBrightnessThrottlingData);
    }

    /**
     * @return Auto brightness darkening light debounce
     */
@@ -1503,6 +1523,7 @@ public class DisplayDeviceConfig {
                loadBrightnessConstraintsFromConfigXml();
                loadBrightnessMap(config);
                loadBrightnessThrottlingMap(config);
                loadConcurrentDisplaysBrightnessThrottlingMap(config);
                loadHighBrightnessModeData(config);
                loadQuirks(config);
                loadBrightnessRamps(config);
@@ -1714,13 +1735,13 @@ public class DisplayDeviceConfig {
    private void loadBrightnessThrottlingMap(DisplayConfiguration config) {
        final ThermalThrottling throttlingConfig = config.getThermalThrottling();
        if (throttlingConfig == null) {
            Slog.i(TAG, "no thermal throttling config found");
            Slog.i(TAG, "No thermal throttling config found");
            return;
        }

        final BrightnessThrottlingMap map = throttlingConfig.getBrightnessThrottlingMap();
        if (map == null) {
            Slog.i(TAG, "no brightness throttling map found");
            Slog.i(TAG, "No brightness throttling map found");
            return;
        }

@@ -1747,6 +1768,43 @@ public class DisplayDeviceConfig {
        }
    }

    private void loadConcurrentDisplaysBrightnessThrottlingMap(DisplayConfiguration config) {
        final ThermalThrottling throttlingConfig = config.getThermalThrottling();
        if (throttlingConfig == null) {
            Slog.i(TAG, "No concurrent displays thermal throttling config found");
            return;
        }

        final BrightnessThrottlingMap map =
                throttlingConfig.getConcurrentDisplaysBrightnessThrottlingMap();
        if (map == null) {
            Slog.i(TAG, "No concurrent displays brightness throttling map found");
            return;
        }

        final List<BrightnessThrottlingPoint> points = map.getBrightnessThrottlingPoint();
        // At least 1 point is guaranteed by the display device config schema
        List<BrightnessThrottlingData.ThrottlingLevel> throttlingLevels =
                new ArrayList<>(points.size());

        boolean badConfig = false;
        for (BrightnessThrottlingPoint point : points) {
            ThermalStatus status = point.getThermalStatus();
            if (!thermalStatusIsValid(status)) {
                badConfig = true;
                break;
            }

            throttlingLevels.add(new BrightnessThrottlingData.ThrottlingLevel(
                    convertThermalStatus(status), point.getBrightness().floatValue()));
        }

        if (!badConfig) {
            mConcurrentDisplaysBrightnessThrottlingData =
                    BrightnessThrottlingData.create(throttlingLevels);
        }
    }

    private void loadRefreshRateSetting(DisplayConfiguration config) {
        final RefreshRateConfigs refreshRateConfigs =
                (config == null) ? null : config.getRefreshRate();
@@ -2529,7 +2587,8 @@ public class DisplayDeviceConfig {
        }
    }

    private @PowerManager.ThermalStatus int convertThermalStatus(ThermalStatus value) {
    @VisibleForTesting
    static @PowerManager.ThermalStatus int convertThermalStatus(ThermalStatus value) {
        if (value == null) {
            return PowerManager.THERMAL_STATUS_NONE;
        }
@@ -2855,7 +2914,8 @@ public class DisplayDeviceConfig {
            return throttlingLevels.hashCode();
        }

        private BrightnessThrottlingData(List<ThrottlingLevel> inLevels) {
        @VisibleForTesting
        BrightnessThrottlingData(List<ThrottlingLevel> inLevels) {
            throttlingLevels = new ArrayList<>(inLevels.size());
            for (ThrottlingLevel level : inLevels) {
                throttlingLevels.add(new ThrottlingLevel(level.thermalStatus, level.brightness));
+7 −0
Original line number Diff line number Diff line
@@ -885,6 +885,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                updatePowerState();
            }
        });

        // TODO (b/265793751): Re-create BrightnessTracker if we're enetering/exiting concurrent
        // displays mode
    }

    /**
@@ -943,6 +946,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                        return mDisplayDeviceConfig.getHdrBrightnessFromSdr(sdrBrightness);
                    }
                });
        // TODO (b/265793751): Use the appropriate throttling data if we're in concurrent displays
        // mode
        mBrightnessThrottler.resetThrottlingData(
                mDisplayDeviceConfig.getBrightnessThrottlingData(), mUniqueDisplayId);
    }
@@ -2048,6 +2053,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
    private BrightnessThrottler createBrightnessThrottlerLocked() {
        final DisplayDevice device = mLogicalDisplay.getPrimaryDisplayDeviceLocked();
        final DisplayDeviceConfig ddConfig = device.getDisplayDeviceConfig();
        // TODO (b/265793751): Use the appropriate throttling data if we're in concurrent displays
        // mode
        final DisplayDeviceConfig.BrightnessThrottlingData data =
                ddConfig != null ? ddConfig.getBrightnessThrottlingData() : null;
        return new BrightnessThrottler(mHandler, data,
+7 −0
Original line number Diff line number Diff line
@@ -732,6 +732,9 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
                updatePowerState();
            }
        });

        // TODO (b/265793751): Re-create BrightnessTracker if we're enetering/exiting concurrent
        // displays mode
    }

    /**
@@ -783,6 +786,8 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
                        return mDisplayDeviceConfig.getHdrBrightnessFromSdr(sdrBrightness);
                    }
                });
        // TODO (b/265793751): Use the appropriate throttling data if we're in concurrent displays
        // mode
        mBrightnessThrottler.resetThrottlingData(
                mDisplayDeviceConfig.getBrightnessThrottlingData(), mUniqueDisplayId);
    }
@@ -1755,6 +1760,8 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
    private BrightnessThrottler createBrightnessThrottlerLocked() {
        final DisplayDevice device = mLogicalDisplay.getPrimaryDisplayDeviceLocked();
        final DisplayDeviceConfig ddConfig = device.getDisplayDeviceConfig();
        // TODO (b/265793751): Use the appropriate throttling data if we're in concurrent displays
        // mode
        final DisplayDeviceConfig.BrightnessThrottlingData data =
                ddConfig != null ? ddConfig.getBrightnessThrottlingData() : null;
        return new BrightnessThrottler(mHandler, data,
+5 −2
Original line number Diff line number Diff line
@@ -202,12 +202,15 @@
    </xs:simpleType>

    <xs:complexType name="thermalThrottling">
        <xs:complexType>
        <xs:sequence>
            <xs:element type="brightnessThrottlingMap" name="brightnessThrottlingMap">
                <xs:annotation name="nonnull"/>
                <xs:annotation name="final"/>
            </xs:element>
        </xs:complexType>
            <xs:element type="brightnessThrottlingMap" name="concurrentDisplaysBrightnessThrottlingMap">
                <xs:annotation name="final"/>
            </xs:element>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="brightnessThrottlingMap">
+2 −0
Original line number Diff line number Diff line
@@ -237,7 +237,9 @@ package com.android.server.display.config {
  public class ThermalThrottling {
    ctor public ThermalThrottling();
    method @NonNull public final com.android.server.display.config.BrightnessThrottlingMap getBrightnessThrottlingMap();
    method public final com.android.server.display.config.BrightnessThrottlingMap getConcurrentDisplaysBrightnessThrottlingMap();
    method public final void setBrightnessThrottlingMap(@NonNull com.android.server.display.config.BrightnessThrottlingMap);
    method public final void setConcurrentDisplaysBrightnessThrottlingMap(com.android.server.display.config.BrightnessThrottlingMap);
  }

  public class ThresholdPoint {
Loading