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

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

Merge "Add HDR values to BrightnessEvent" into main

parents ea74f962 37b9288d
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -1611,6 +1611,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        mBrightnessRangeController.onBrightnessChanged(brightnessState, unthrottledBrightnessState,
                clampedState);

        // Initial HDR value to be replaced with calculated HDR value if one exists.
        float hdrBrightness = brightnessState;

        // Animate the screen brightness when the screen is on or dozing.
        // Skip the animation when the screen is off or suspended.
        boolean brightnessAdjusted = false;
@@ -1670,6 +1673,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                // done in HdrBrightnessModifier.
                // customAnimationRate and reason also handled by HdrBrightnessModifier
                animateValue = clampedState.getHdrBrightness();
                hdrBrightness = animateValue;
            } else if (mBrightnessRangeController.getHighBrightnessMode()
                    == BrightnessInfo.HIGH_BRIGHTNESS_MODE_HDR
                    && (mBrightnessReasonTemp.getModifier() & BrightnessReason.MODIFIER_DIMMED) == 0
@@ -1678,6 +1682,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                // We want to scale HDR brightness level with the SDR level, we also need to restore
                // SDR brightness immediately when entering dim or low power mode.
                animateValue = mBrightnessRangeController.getHdrBrightnessValue();
                hdrBrightness = animateValue;
                customAnimationRate = Math.max(customAnimationRate,
                        mBrightnessRangeController.getHdrTransitionRate());
                mBrightnessReasonTemp.addModifier(BrightnessReason.MODIFIER_HDR);
@@ -1771,8 +1776,11 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        // brightness cap, RBC state, etc.
        mTempBrightnessEvent.setTime(System.currentTimeMillis());
        mTempBrightnessEvent.setBrightness(brightnessState);
        mTempBrightnessEvent.setHdrBrightness(hdrBrightness);
        mTempBrightnessEvent.setNits(
                mDisplayBrightnessController.convertToAdjustedNits(brightnessState));
        mTempBrightnessEvent.setHdrNits(
                mDisplayBrightnessController.convertToAdjustedNits(hdrBrightness));
        final float hbmMax = mBrightnessRangeController.getCurrentBrightnessMax();
        final float clampedMax = Math.min(clampedState.getMaxBrightness(), hbmMax);
        final float brightnessOnAvailableScale = MathUtils.constrainedMap(0.0f, 1.0f,
+31 −3
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.os.SystemClock;
import android.view.Display;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.display.BrightnessSynchronizer;
import com.android.server.display.AutomaticBrightnessController;

import java.text.SimpleDateFormat;
@@ -59,10 +60,12 @@ public final class BrightnessEvent {
    private long mTime;
    private float mLux;
    private float mNits;
    private float mHdrNits;
    private float mPercent;
    private float mPreThresholdLux;
    private float mInitialBrightness;
    private float mBrightness;
    private float mHdrBrightness;
    private float mUnclampedBrightness;
    private float mRecommendedBrightness;
    private float mPreThresholdBrightness;
@@ -108,10 +111,12 @@ public final class BrightnessEvent {
        mLux = that.getLux();
        mPreThresholdLux = that.getPreThresholdLux();
        mNits = that.getNits();
        mHdrNits = that.getHdrNits();
        mPercent = that.getPercent();
        // Brightness values
        mInitialBrightness = that.getInitialBrightness();
        mBrightness = that.getBrightness();
        mHdrBrightness = that.getHdrBrightness();
        mUnclampedBrightness = that.getUnclampedBrightness();
        mRecommendedBrightness = that.getRecommendedBrightness();
        mPreThresholdBrightness = that.getPreThresholdBrightness();
@@ -147,10 +152,12 @@ public final class BrightnessEvent {
        mLux = INVALID_LUX;
        mPreThresholdLux = 0;
        mNits = INVALID_NITS;
        mHdrNits = INVALID_NITS;
        mPercent = -1f;
        // Brightness values
        mInitialBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT;
        mBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT;
        mHdrBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT;
        mUnclampedBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT;
        mRecommendedBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT;
        mPreThresholdBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT;
@@ -193,9 +200,12 @@ public final class BrightnessEvent {
                && Float.floatToRawIntBits(mPreThresholdLux)
                == Float.floatToRawIntBits(that.mPreThresholdLux)
                && Float.floatToRawIntBits(mNits) == Float.floatToRawIntBits(that.mNits)
                && Float.floatToRawIntBits(mHdrNits) == Float.floatToRawIntBits(that.mHdrNits)
                && Float.floatToRawIntBits(mPercent) == Float.floatToRawIntBits(that.mPercent)
                && Float.floatToRawIntBits(mBrightness)
                == Float.floatToRawIntBits(that.mBrightness)
                && Float.floatToRawIntBits(mHdrBrightness)
                == Float.floatToRawIntBits(that.mHdrBrightness)
                && Float.floatToRawIntBits(mUnclampedBrightness)
                == Float.floatToRawIntBits(that.mUnclampedBrightness)
                && Float.floatToRawIntBits(mRecommendedBrightness)
@@ -224,11 +234,13 @@ public final class BrightnessEvent {
     * @return A stringified BrightnessEvent
     */
    public String toString(boolean includeTime) {
        final boolean isHdrSdrSame =
                BrightnessSynchronizer.floatEquals(mBrightness, mHdrBrightness);
        return (includeTime ? FORMAT.format(new Date(mTime)) + " - " : "")
                + "BrightnessEvent: "
                + "brt=" + mBrightness + ((mFlags & FLAG_USER_SET) != 0 ? "(user_set)" : "") + "("
                + mPercent + "%)"
                + ", nits= " + mNits
                + mPercent + "%)" + (isHdrSdrSame ? "" : "(hdr=" + mHdrBrightness + ")")
                + ", nits=" + mNits + (isHdrSdrSame ? "" : "(hdr=" + mHdrNits + ")")
                + ", lux=" + mLux
                + ", reason=" + mReason.toString(mAdjustmentFlags)
                + ", strat=" + mDisplayBrightnessStrategyName
@@ -348,6 +360,14 @@ public final class BrightnessEvent {
        this.mBrightness = brightness;
    }

    public float getHdrBrightness() {
        return mHdrBrightness;
    }

    public void setHdrBrightness(float brightness) {
        this.mHdrBrightness = brightness;
    }

    public float getUnclampedBrightness() {
        return mUnclampedBrightness;
    }
@@ -371,6 +391,14 @@ public final class BrightnessEvent {
        return mNits;
    }

    public void setHdrNits(float nits) {
        this.mHdrNits = nits;
    }

    public float getHdrNits() {
        return mHdrNits;
    }

    public float getRecommendedBrightness() {
        return mRecommendedBrightness;
    }
+18 −1
Original line number Diff line number Diff line
@@ -51,11 +51,13 @@ public final class BrightnessEventTest {
        mBrightnessEvent.setLux(100.0f);
        mBrightnessEvent.setPercent(46.5f);
        mBrightnessEvent.setNits(893.8f);
        mBrightnessEvent.setHdrNits(893.8f);
        mBrightnessEvent.setUnclampedBrightness(0.65f);
        mBrightnessEvent.setPreThresholdLux(150.0f);
        mBrightnessEvent.setTime(System.currentTimeMillis());
        mBrightnessEvent.setInitialBrightness(25.0f);
        mBrightnessEvent.setBrightness(0.6f);
        mBrightnessEvent.setHdrBrightness(0.6f);
        mBrightnessEvent.setRecommendedBrightness(0.6f);
        mBrightnessEvent.setHbmMax(0.62f);
        mBrightnessEvent.setRbcStrength(-1);
@@ -92,6 +94,21 @@ public final class BrightnessEventTest {
                        + "rbcStrength=-1, powerFactor=0.2, physDisp=display_name(987654321), "
                        + "logicalId=1, slowChange=true, rampSpeed=0.3";
        assertEquals(expectedString, actualString);

        // Now check with optional HDR logging (when HDR brightness differs from brightness)
        mBrightnessEvent.setHdrBrightness(0.7f);
        mBrightnessEvent.setHdrNits(1093.8f);
        actualString = mBrightnessEvent.toString(false);
        String expectedHdrString =
                "BrightnessEvent: brt=0.6(46.5%)(hdr=0.7), nits=893.8(hdr=1093.8), lux=100.0, "
                        + "reason=doze [ low_pwr ], strat=strategy_name, state=ON, "
                        + "stateReason=DEFAULT_POLICY, "
                        + "policy=BRIGHT, flags=, initBrt=25.0, rcmdBrt=0.6, preBrt=NaN, "
                        + "preLux=150.0, wasShortTermModelActive=true, autoBrightness=true (idle), "
                        + "unclampedBrt=0.65, hbmMax=0.62, hbmMode=off, thrmMax=0.65, "
                        + "rbcStrength=-1, powerFactor=0.2, physDisp=display_name(987654321), "
                        + "logicalId=1, slowChange=true, rampSpeed=0.3";
        assertEquals(expectedHdrString, actualString);
    }

    @Test