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

Commit 9b0e554e authored by Piotr Wilczyński's avatar Piotr Wilczyński Committed by Automerger Merge Worker
Browse files

Merge "Pass brightness ramp rate to follower displays" into udc-qpr-dev am: 5dc4f71d

parents 14e1b0ef 5dc4f71d
Loading
Loading
Loading
Loading
+33 −14
Original line number Diff line number Diff line
@@ -512,6 +512,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
    // of the lead display that this DPC should follow.
    private float mBrightnessToFollow;

    // Indicates whether we should ramp slowly to the brightness value to follow.
    private boolean mBrightnessToFollowSlowChange;

    // The last auto brightness adjustment that was set by the user and not temporary. Set to
    // Float.NaN when an auto-brightness adjustment hasn't been recorded yet.
    private float mAutoBrightnessAdjustment;
@@ -812,7 +815,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
    }

    @Override
    public void setBrightnessToFollow(float leadDisplayBrightness, float nits, float ambientLux) {
    public void setBrightnessToFollow(float leadDisplayBrightness, float nits, float ambientLux,
            boolean slowChange) {
        mBrightnessRangeController.onAmbientLuxChange(ambientLux);
        if (nits < 0) {
            mBrightnessToFollow = leadDisplayBrightness;
@@ -825,6 +829,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                mBrightnessToFollow = leadDisplayBrightness;
            }
        }
        mBrightnessToFollowSlowChange = slowChange;
        sendUpdatePowerState();
    }

@@ -842,7 +847,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
            mDisplayBrightnessFollowers.remove(follower.getDisplayId());
            mHandler.postAtTime(() -> follower.setBrightnessToFollow(
                    PowerManager.BRIGHTNESS_INVALID_FLOAT, /* nits= */ -1,
                    /* ambientLux= */ 0), mClock.uptimeMillis());
                    /* ambientLux= */ 0, /* slowChange= */ false), mClock.uptimeMillis());
        }
    }

@@ -852,7 +857,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
            DisplayPowerControllerInterface follower = mDisplayBrightnessFollowers.valueAt(i);
            mHandler.postAtTime(() -> follower.setBrightnessToFollow(
                    PowerManager.BRIGHTNESS_INVALID_FLOAT, /* nits= */ -1,
                    /* ambientLux= */ 0), mClock.uptimeMillis());
                    /* ambientLux= */ 0, /* slowChange= */ false), mClock.uptimeMillis());
        }
        mDisplayBrightnessFollowers.clear();
    }
@@ -1559,6 +1564,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        final int oldState = mPowerState.getScreenState();
        animateScreenStateChange(state, performScreenOffTransition);
        state = mPowerState.getScreenState();
        boolean slowChange = false;

        if (state == Display.STATE_OFF) {
            brightnessState = PowerManager.BRIGHTNESS_OFF_FLOAT;
@@ -1567,6 +1573,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call

        if (Float.isNaN(brightnessState) && isValidBrightnessValue(mBrightnessToFollow)) {
            brightnessState = mBrightnessToFollow;
            slowChange = mBrightnessToFollowSlowChange;
            mBrightnessReasonTemp.setReason(BrightnessReason.REASON_FOLLOWER);
        }

@@ -1661,7 +1668,6 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        float rawBrightnessState = brightnessState;

        // Apply auto-brightness.
        boolean slowChange = false;
        if (Float.isNaN(brightnessState)) {
            float newAutoBrightnessAdjustment = autoBrightnessAdjustment;
            if (autoBrightnessEnabled) {
@@ -1740,6 +1746,14 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
            mBrightnessReasonTemp.setReason(BrightnessReason.REASON_MANUAL);
        }

        float ambientLux = mAutomaticBrightnessController == null ? 0
                : mAutomaticBrightnessController.getAmbientLux();
        for (int i = 0; i < displayBrightnessFollowers.size(); i++) {
            DisplayPowerControllerInterface follower = displayBrightnessFollowers.valueAt(i);
            follower.setBrightnessToFollow(rawBrightnessState, convertToNits(rawBrightnessState),
                    ambientLux, slowChange);
        }

        // Now that a desired brightness has been calculated, apply brightness throttling. The
        // dimming and low power transformations that follow can only dim brightness further.
        //
@@ -1762,14 +1776,6 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
            mAppliedThrottling = false;
        }

        float ambientLux = mAutomaticBrightnessController == null ? 0
                : mAutomaticBrightnessController.getAmbientLux();
        for (int i = 0; i < displayBrightnessFollowers.size(); i++) {
            DisplayPowerControllerInterface follower = displayBrightnessFollowers.valueAt(i);
            follower.setBrightnessToFollow(rawBrightnessState, convertToNits(rawBrightnessState),
                    ambientLux);
        }

        if (updateScreenBrightnessSetting) {
            // Tell the rest of the system about the new brightness in case we had to change it
            // for things like auto-brightness or high-brightness-mode. Note that we do this
@@ -2157,8 +2163,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        final DisplayDeviceConfig.HighBrightnessModeData hbmData =
                ddConfig != null ? ddConfig.getHighBrightnessModeData() : null;
        final DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked();
        return new HighBrightnessModeController(mHandler, info.width, info.height, displayToken,
                displayUniqueId, PowerManager.BRIGHTNESS_MIN, PowerManager.BRIGHTNESS_MAX, hbmData,
        return mInjector.getHighBrightnessModeController(mHandler, info.width, info.height,
                displayToken, displayUniqueId, PowerManager.BRIGHTNESS_MIN,
                PowerManager.BRIGHTNESS_MAX, hbmData,
                new HighBrightnessModeController.HdrBrightnessDeviceConfig() {
                    @Override
                    public float getHdrBrightnessFromSdr(
@@ -2949,6 +2956,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                + mPendingScreenBrightnessSetting);
        pw.println("  mTemporaryScreenBrightness=" + mTemporaryScreenBrightness);
        pw.println("  mBrightnessToFollow=" + mBrightnessToFollow);
        pw.println("  mBrightnessToFollowSlowChange=" + mBrightnessToFollowSlowChange);
        pw.println("  mAutoBrightnessAdjustment=" + mAutoBrightnessAdjustment);
        pw.println("  mBrightnessReason=" + mBrightnessReason);
        pw.println("  mTemporaryAutoBrightnessAdjustment=" + mTemporaryAutoBrightnessAdjustment);
@@ -3528,6 +3536,17 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                    brightnessMapper
            );
        }

        HighBrightnessModeController getHighBrightnessModeController(Handler handler, int width,
                int height, IBinder displayToken, String displayUniqueId, float brightnessMin,
                float brightnessMax, DisplayDeviceConfig.HighBrightnessModeData hbmData,
                HighBrightnessModeController.HdrBrightnessDeviceConfig hdrBrightnessCfg,
                Runnable hbmChangeCallback, HighBrightnessModeMetadata hbmMetadata,
                Context context) {
            return new HighBrightnessModeController(handler, width, height, displayToken,
                    displayUniqueId, brightnessMin, brightnessMax, hbmData, hdrBrightnessCfg,
                    hbmChangeCallback, hbmMetadata, context);
        }
    }

    static class CachedBrightnessInfo {
+42 −16
Original line number Diff line number Diff line
@@ -435,6 +435,9 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
    @Nullable
    private BrightnessMappingStrategy mIdleModeBrightnessMapper;

    // Indicates whether we should ramp slowly to the brightness value to follow.
    private boolean mBrightnessToFollowSlowChange;

    private boolean mIsRbcActive;

    // Animators.
@@ -1272,6 +1275,7 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
        // actual state instead of the desired one.
        animateScreenStateChange(state, mDisplayStateController.shouldPerformScreenOffTransition());
        state = mPowerState.getScreenState();
        boolean slowChange = false;
        final boolean userSetBrightnessChanged = mDisplayBrightnessController
                .updateUserSetScreenBrightness();

@@ -1281,6 +1285,11 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
        float rawBrightnessState = displayBrightnessState.getBrightness();
        mBrightnessReasonTemp.set(displayBrightnessState.getBrightnessReason());

        if (displayBrightnessState.getBrightnessReason().getReason()
                == BrightnessReason.REASON_FOLLOWER) {
            slowChange = mBrightnessToFollowSlowChange;
        }

        // Take note if the short term model was already active before applying the current
        // request changes.
        final boolean wasShortTermModelActive =
@@ -1305,7 +1314,6 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
        boolean updateScreenBrightnessSetting = false;
        float currentBrightnessSetting = mDisplayBrightnessController.getCurrentBrightness();
        // Apply auto-brightness.
        boolean slowChange = false;
        int brightnessAdjustmentFlags = 0;
        if (Float.isNaN(brightnessState)) {
            if (mAutomaticBrightnessStrategy.isAutoBrightnessEnabled()) {
@@ -1322,10 +1330,13 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
                    brightnessAdjustmentFlags =
                            mAutomaticBrightnessStrategy.getAutoBrightnessAdjustmentReasonsFlags();
                    updateScreenBrightnessSetting = currentBrightnessSetting != brightnessState;
                    mAutomaticBrightnessStrategy.setAutoBrightnessApplied(true);
                    mBrightnessReasonTemp.setReason(BrightnessReason.REASON_AUTOMATIC);
                    if (mScreenOffBrightnessSensorController != null) {
                        mScreenOffBrightnessSensorController.setLightSensorEnabled(false);
                    }
                } else {
                    mAutomaticBrightnessStrategy.setAutoBrightnessApplied(false);
                }
            }
        } else {
@@ -1333,6 +1344,7 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
            // to clamping so that they don't go beyond the current max as specified by HBM
            // Controller.
            brightnessState = clampScreenBrightness(brightnessState);
            mAutomaticBrightnessStrategy.setAutoBrightnessApplied(false);
        }

        // Use default brightness when dozing unless overridden.
@@ -1372,6 +1384,15 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
            mBrightnessReasonTemp.setReason(BrightnessReason.REASON_MANUAL);
        }

        float ambientLux = mAutomaticBrightnessController == null ? 0
                : mAutomaticBrightnessController.getAmbientLux();
        for (int i = 0; i < displayBrightnessFollowers.size(); i++) {
            DisplayPowerControllerInterface follower = displayBrightnessFollowers.valueAt(i);
            follower.setBrightnessToFollow(rawBrightnessState,
                    mDisplayBrightnessController.convertToNits(rawBrightnessState),
                    ambientLux, slowChange);
        }

        // Now that a desired brightness has been calculated, apply brightness throttling. The
        // dimming and low power transformations that follow can only dim brightness further.
        //
@@ -1394,15 +1415,6 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
            mAppliedThrottling = false;
        }

        float ambientLux = mAutomaticBrightnessController == null ? 0
                : mAutomaticBrightnessController.getAmbientLux();
        for (int i = 0; i < displayBrightnessFollowers.size(); i++) {
            DisplayPowerControllerInterface follower = displayBrightnessFollowers.valueAt(i);
            follower.setBrightnessToFollow(rawBrightnessState,
                    mDisplayBrightnessController.convertToNits(rawBrightnessState),
                    ambientLux);
        }

        if (updateScreenBrightnessSetting) {
            // Tell the rest of the system about the new brightness in case we had to change it
            // for things like auto-brightness or high-brightness-mode. Note that we do this
@@ -1804,9 +1816,9 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
        final DisplayDeviceConfig.HighBrightnessModeData hbmData =
                ddConfig != null ? ddConfig.getHighBrightnessModeData() : null;
        final DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked();
        return new HighBrightnessModeController(mHandler, info.width, info.height, displayToken,
                displayUniqueId, PowerManager.BRIGHTNESS_MIN, PowerManager.BRIGHTNESS_MAX, hbmData,
                (sdrBrightness, maxDesiredHdrSdrRatio) ->
        return mInjector.getHighBrightnessModeController(mHandler, info.width, info.height,
                displayToken, displayUniqueId, PowerManager.BRIGHTNESS_MIN,
                PowerManager.BRIGHTNESS_MAX, hbmData, (sdrBrightness, maxDesiredHdrSdrRatio) ->
                        mDisplayDeviceConfig.getHdrBrightnessFromSdr(sdrBrightness,
                                maxDesiredHdrSdrRatio), modeChangeCallback, hbmMetadata, mContext);
    }
@@ -2189,7 +2201,8 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
    }

    @Override
    public void setBrightnessToFollow(float leadDisplayBrightness, float nits, float ambientLux) {
    public void setBrightnessToFollow(float leadDisplayBrightness, float nits, float ambientLux,
            boolean slowChange) {
        mBrightnessRangeController.onAmbientLuxChange(ambientLux);
        if (nits < 0) {
            mDisplayBrightnessController.setBrightnessToFollow(leadDisplayBrightness);
@@ -2202,6 +2215,7 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
                mDisplayBrightnessController.setBrightnessToFollow(leadDisplayBrightness);
            }
        }
        mBrightnessToFollowSlowChange = slowChange;
        sendUpdatePowerState();
    }

@@ -2261,7 +2275,7 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
            mDisplayBrightnessFollowers.remove(follower.getDisplayId());
            mHandler.postAtTime(() -> follower.setBrightnessToFollow(
                    PowerManager.BRIGHTNESS_INVALID_FLOAT, /* nits= */ -1,
                    /* ambientLux= */ 0), mClock.uptimeMillis());
                    /* ambientLux= */ 0, /* slowChange= */ false), mClock.uptimeMillis());
        }
    }

@@ -2271,7 +2285,7 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
            DisplayPowerControllerInterface follower = mDisplayBrightnessFollowers.valueAt(i);
            mHandler.postAtTime(() -> follower.setBrightnessToFollow(
                    PowerManager.BRIGHTNESS_INVALID_FLOAT, /* nits= */ -1,
                    /* ambientLux= */ 0), mClock.uptimeMillis());
                    /* ambientLux= */ 0, /* slowChange= */ false), mClock.uptimeMillis());
        }
        mDisplayBrightnessFollowers.clear();
    }
@@ -2341,6 +2355,7 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
        pw.println("  mReportedToPolicy="
                + reportedToPolicyToString(mReportedScreenStateToPolicy));
        pw.println("  mIsRbcActive=" + mIsRbcActive);
        pw.println("  mBrightnessToFollowSlowChange=" + mBrightnessToFollowSlowChange);
        IndentingPrintWriter ipw = new IndentingPrintWriter(pw, "    ");
        mAutomaticBrightnessStrategy.dump(ipw);

@@ -2892,6 +2907,17 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
                    brightnessMapper
            );
        }

        HighBrightnessModeController getHighBrightnessModeController(Handler handler, int width,
                int height, IBinder displayToken, String displayUniqueId, float brightnessMin,
                float brightnessMax, DisplayDeviceConfig.HighBrightnessModeData hbmData,
                HighBrightnessModeController.HdrBrightnessDeviceConfig hdrBrightnessCfg,
                Runnable hbmChangeCallback, HighBrightnessModeMetadata hbmMetadata,
                Context context) {
            return new HighBrightnessModeController(handler, width, height, displayToken,
                    displayUniqueId, brightnessMin, brightnessMax, hbmData, hdrBrightnessCfg,
                    hbmChangeCallback, hbmMetadata, context);
        }
    }

    static class CachedBrightnessInfo {
+3 −1
Original line number Diff line number Diff line
@@ -201,8 +201,10 @@ public interface DisplayPowerControllerInterface {
     * @param nits The brightness value in nits if the device supports nits. Set to a negative
     *             number otherwise.
     * @param ambientLux The lux value that will be passed to {@link HighBrightnessModeController}
     * @param slowChange Indicates whether we should slowly animate to the given brightness value.
     */
    void setBrightnessToFollow(float leadDisplayBrightness, float nits, float ambientLux);
    void setBrightnessToFollow(float leadDisplayBrightness, float nits, float ambientLux,
            boolean slowChange);

    /**
     * Add an additional display that will copy the brightness value from this display. This is used
+1 −4
Original line number Diff line number Diff line
@@ -287,8 +287,6 @@ public class AutomaticBrightnessStrategy {
        mAutoBrightnessAdjustmentReasonsFlags = isTemporaryAutoBrightnessAdjustmentApplied()
                ? BrightnessReason.ADJUSTMENT_AUTO_TEMP
                : BrightnessReason.ADJUSTMENT_AUTO;
        mAppliedAutoBrightness = BrightnessUtils.isValidBrightnessValue(brightnessState)
                || brightnessState == PowerManager.BRIGHTNESS_OFF_FLOAT;
        float newAutoBrightnessAdjustment =
                (mAutomaticBrightnessController != null)
                        ? mAutomaticBrightnessController.getAutomaticScreenBrightnessAdjustment()
@@ -345,8 +343,7 @@ public class AutomaticBrightnessStrategy {
    /**
     * Sets if the auto-brightness is applied on the latest brightness change.
     */
    @VisibleForTesting
    void setAutoBrightnessApplied(boolean autoBrightnessApplied) {
    public void setAutoBrightnessApplied(boolean autoBrightnessApplied) {
        mAppliedAutoBrightness = autoBrightnessApplied;
    }

+169 −45

File changed.

Preview size limit exceeded, changes collapsed.

Loading