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

Commit 6da0e275 authored by Alec Mouri's avatar Alec Mouri
Browse files

Send dimming ratio to composer instead of white point nits

* Send the dimming ratio over to composer as the HWC api is changing to
  not expose the notion of nits to composer, as the white point nits are
  part of logical SF state that does not map as nicely to display
  hardware
* Fixes an issue where scheduling a recomposite for a frame when
  brightness changes is contingent on the presence of HDR layers, which
  is not valid when an HDR layer exits the scene, but DisplayManager
  animates the display brightness down to the SDR white point.

Bug: 217961164
Test: builds, boots
Test: HDR test videos on youtube
Change-Id: Icc07b00f60859bbd3ee078cd2bb793eda42e7781
parent 7c60b886
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -153,9 +153,11 @@ struct OutputLayerCompositionState {
    // Timestamp for when the layer is queued for client composition
    nsecs_t clientCompositionTimestamp{0};

    // White point of the layer, in nits.
    static constexpr float kDefaultWhitePointNits = 200.f;
    float whitePointNits = kDefaultWhitePointNits;
    // Dimming ratio of the layer from [0, 1]
    static constexpr float kDefaultDimmingRatio = 1.f;
    float dimmingRatio = kDefaultDimmingRatio;
};

} // namespace compositionengine::impl
+11 −7
Original line number Diff line number Diff line
@@ -324,9 +324,14 @@ void OutputLayer::updateCompositionState(

    // For hdr content, treat the white point as the display brightness - HDR content should not be
    // boosted or dimmed.
    if (isHdrDataspace(state.dataspace)) {
    if (isHdrDataspace(state.dataspace) ||
        getOutput().getState().displayBrightnessNits == getOutput().getState().sdrWhitePointNits) {
        state.dimmingRatio = 1.f;
        state.whitePointNits = getOutput().getState().displayBrightnessNits;
    } else {
        state.dimmingRatio = std::clamp(getOutput().getState().sdrWhitePointNits /
                                                getOutput().getState().displayBrightnessNits,
                                        0.f, 1.f);
        state.whitePointNits = getOutput().getState().sdrWhitePointNits;
    }

@@ -502,13 +507,12 @@ void OutputLayer::writeOutputDependentPerFrameStateToHWC(HWC2::Layer* hwcLayer)
    }

    // Don't dim cached layers
    const auto whitePointNits = outputDependentState.overrideInfo.buffer
            ? getOutput().getState().displayBrightnessNits
            : outputDependentState.whitePointNits;
    const auto dimmingRatio =
            outputDependentState.overrideInfo.buffer ? 1.f : outputDependentState.dimmingRatio;

    if (auto error = hwcLayer->setWhitePointNits(whitePointNits); error != hal::Error::NONE) {
        ALOGE("[%s] Failed to set white point %f: %s (%d)", getLayerFE().getDebugName(),
              whitePointNits, to_string(error).c_str(), static_cast<int32_t>(error));
    if (auto error = hwcLayer->setBrightness(dimmingRatio); error != hal::Error::NONE) {
        ALOGE("[%s] Failed to set brightness %f: %s (%d)", getLayerFE().getDebugName(),
              dimmingRatio, to_string(error).c_str(), static_cast<int32_t>(error));
    }
}

+1 −1
Original line number Diff line number Diff line
@@ -74,7 +74,7 @@ public:
    MOCK_METHOD1(setColorTransform, Error(const android::mat4&));
    MOCK_METHOD3(setLayerGenericMetadata,
                 Error(const std::string&, bool, const std::vector<uint8_t>&));
    MOCK_METHOD1(setWhitePointNits, Error(float));
    MOCK_METHOD1(setBrightness, Error(float));
    MOCK_METHOD1(setBlockingRegion, Error(const android::Region&));
};

+10 −7
Original line number Diff line number Diff line
@@ -751,6 +751,8 @@ struct OutputLayerWriteStateToHWCTest : public OutputLayerTest {
    static constexpr bool kLayerGenericMetadata2Mandatory = true;
    static constexpr float kWhitePointNits = 200.f;
    static constexpr float kDisplayBrightnessNits = 400.f;
    static constexpr float kLayerBrightness = kWhitePointNits / kDisplayBrightnessNits;
    static constexpr float kFullLayerBrightness = 1.f;

    static const half4 kColor;
    static const Rect kDisplayFrame;
@@ -782,6 +784,7 @@ struct OutputLayerWriteStateToHWCTest : public OutputLayerTest {
        outputLayerState.outputSpaceVisibleRegion = kOutputSpaceVisibleRegion;
        outputLayerState.dataspace = kDataspace;
        outputLayerState.whitePointNits = kWhitePointNits;
        outputLayerState.dimmingRatio = kLayerBrightness;

        mLayerFEState.blendMode = kBlendMode;
        mLayerFEState.alpha = kAlpha;
@@ -846,11 +849,11 @@ struct OutputLayerWriteStateToHWCTest : public OutputLayerTest {
                                   ui::Dataspace dataspace = kDataspace,
                                   const Region& visibleRegion = kOutputSpaceVisibleRegion,
                                   const Region& surfaceDamage = kSurfaceDamage,
                                   float whitePointNits = kWhitePointNits,
                                   float brightness = kLayerBrightness,
                                   const Region& blockingRegion = Region()) {
        EXPECT_CALL(*mHwcLayer, setVisibleRegion(RegionEq(visibleRegion))).WillOnce(Return(kError));
        EXPECT_CALL(*mHwcLayer, setDataspace(dataspace)).WillOnce(Return(kError));
        EXPECT_CALL(*mHwcLayer, setWhitePointNits(whitePointNits)).WillOnce(Return(kError));
        EXPECT_CALL(*mHwcLayer, setBrightness(brightness)).WillOnce(Return(kError));
        EXPECT_CALL(*mHwcLayer, setColorTransform(kColorTransform))
                .WillOnce(Return(unsupported == SimulateUnsupported::ColorTransform
                                         ? hal::Error::UNSUPPORTED
@@ -1114,7 +1117,7 @@ TEST_F(OutputLayerWriteStateToHWCTest, overriddenSkipLayerDoesNotSendBuffer) {
    expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform,
                              kOverrideBlendMode, kSkipAlpha);
    expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
                              kOverrideSurfaceDamage, kDisplayBrightnessNits);
                              kOverrideSurfaceDamage, kFullLayerBrightness);
    expectSetHdrMetadataAndBufferCalls();
    expectSetCompositionTypeCall(Composition::DEVICE);
    EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(false));
@@ -1130,7 +1133,7 @@ TEST_F(OutputLayerWriteStateToHWCTest, overriddenSkipLayerForSolidColorDoesNotSe
    expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform,
                              kOverrideBlendMode, kSkipAlpha);
    expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
                              kOverrideSurfaceDamage, kDisplayBrightnessNits);
                              kOverrideSurfaceDamage, kFullLayerBrightness);
    expectSetHdrMetadataAndBufferCalls();
    expectSetCompositionTypeCall(Composition::DEVICE);
    EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(false));
@@ -1146,7 +1149,7 @@ TEST_F(OutputLayerWriteStateToHWCTest, includesOverrideInfoIfPresent) {
    expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform,
                              kOverrideBlendMode, kOverrideAlpha);
    expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
                              kOverrideSurfaceDamage, kDisplayBrightnessNits);
                              kOverrideSurfaceDamage, kFullLayerBrightness);
    expectSetHdrMetadataAndBufferCalls(kOverrideHwcSlot, kOverrideBuffer, kOverrideFence);
    expectSetCompositionTypeCall(Composition::DEVICE);
    EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(false));
@@ -1162,7 +1165,7 @@ TEST_F(OutputLayerWriteStateToHWCTest, includesOverrideInfoForSolidColorIfPresen
    expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform,
                              kOverrideBlendMode, kOverrideAlpha);
    expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion,
                              kOverrideSurfaceDamage, kDisplayBrightnessNits);
                              kOverrideSurfaceDamage, kFullLayerBrightness);
    expectSetHdrMetadataAndBufferCalls(kOverrideHwcSlot, kOverrideBuffer, kOverrideFence);
    expectSetCompositionTypeCall(Composition::DEVICE);
    EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(false));
@@ -1288,7 +1291,7 @@ TEST_F(OutputLayerWriteStateToHWCTest, setBlockingRegion) {

    expectGeometryCommonCalls();
    expectPerFrameCommonCalls(SimulateUnsupported::None, kDataspace, kOutputSpaceVisibleRegion,
                              kSurfaceDamage, kWhitePointNits, blockingRegion);
                              kSurfaceDamage, kLayerBrightness, blockingRegion);
    expectSetHdrMetadataAndBufferCalls();
    EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(false));
    expectSetCompositionTypeCall(Composition::DISPLAY_DECORATION);
+2 −3
Original line number Diff line number Diff line
@@ -1062,9 +1062,8 @@ Error AidlComposer::getClientTargetProperty(
    return Error::NONE;
}

Error AidlComposer::setLayerWhitePointNits(Display display, Layer layer, float whitePointNits) {
    mWriter.setLayerWhitePointNits(translate<int64_t>(display), translate<int64_t>(layer),
                                   whitePointNits);
Error AidlComposer::setLayerBrightness(Display display, Layer layer, float brightness) {
    mWriter.setLayerBrightness(translate<int64_t>(display), translate<int64_t>(layer), brightness);
    return Error::NONE;
}

Loading