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

Commit 9dbf512b authored by Alec Mouri's avatar Alec Mouri Committed by Android (Google) Code Review
Browse files

Merge "Set right dimmingRatio for fp16 input layers without metadata" into main

parents 18a80f97 c282e18f
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ enum class HdrRenderType {
 */
inline HdrRenderType getHdrRenderType(ui::Dataspace dataspace,
                                      std::optional<ui::PixelFormat> pixelFormat,
                                      float hdrSdrRatio = 1.f) {
                                      float hdrSdrRatio = 1.f, bool hasHdrMetadata = false) {
    const auto transfer = dataspace & HAL_DATASPACE_TRANSFER_MASK;
    const auto range = dataspace & HAL_DATASPACE_RANGE_MASK;

@@ -49,7 +49,8 @@ inline HdrRenderType getHdrRenderType(ui::Dataspace dataspace,
                                                                     HAL_DATASPACE_RANGE_EXTENDED);

    if ((dataspace == BT2020_LINEAR_EXT || dataspace == ui::Dataspace::V0_SCRGB) &&
        pixelFormat.has_value() && pixelFormat.value() == ui::PixelFormat::RGBA_FP16) {
        pixelFormat.has_value() && pixelFormat.value() == ui::PixelFormat::RGBA_FP16 &&
        hasHdrMetadata) {
        return HdrRenderType::GENERIC_HDR;
    }

+16 −5
Original line number Diff line number Diff line
@@ -369,8 +369,11 @@ void OutputLayer::updateCompositionState(
                                                      layerFEState->buffer->getPixelFormat()))
                                            : std::nullopt;

    auto hdrRenderType =
            getHdrRenderType(outputState.dataspace, pixelFormat, layerFEState->desiredHdrSdrRatio);
    // prefer querying this from gralloc instead to catch 2094-10 metadata
    const bool hasHdrMetadata = layerFEState->hdrMetadata.validTypes != 0;

    auto hdrRenderType = getHdrRenderType(outputState.dataspace, pixelFormat,
                                          layerFEState->desiredHdrSdrRatio, hasHdrMetadata);

    // Determine the output dependent dataspace for this layer. If it is
    // colorspace agnostic, it just uses the dataspace chosen for the output to
@@ -393,8 +396,8 @@ void OutputLayer::updateCompositionState(
    }

    // re-get HdrRenderType after the dataspace gets changed.
    hdrRenderType =
            getHdrRenderType(state.dataspace, pixelFormat, layerFEState->desiredHdrSdrRatio);
    hdrRenderType = getHdrRenderType(state.dataspace, pixelFormat, layerFEState->desiredHdrSdrRatio,
                                     hasHdrMetadata);

    // For hdr content, treat the white point as the display brightness - HDR content should not be
    // boosted or dimmed.
@@ -416,12 +419,20 @@ void OutputLayer::updateCompositionState(
        state.dimmingRatio = std::min(idealizedMaxHeadroom / deviceHeadroom, 1.0f);
        state.whitePointNits = getOutput().getState().displayBrightnessNits * state.dimmingRatio;
    } else {
        const bool isLayerFp16 = pixelFormat && *pixelFormat == ui::PixelFormat::RGBA_FP16;
        float layerBrightnessNits = getOutput().getState().sdrWhitePointNits;
        // RANGE_EXTENDED can "self-promote" to HDR, but is still rendered for a particular
        // range that we may need to re-adjust to the current display conditions
        // Do NOT do this when we may render fp16 to an fp16 client target, to avoid applying
        // and additional gain to the layer. This is because the fp16 client target should
        // already be adapted to remap 1.0 to the SDR white point in the panel's luminance
        // space.
        if (hdrRenderType == HdrRenderType::DISPLAY_HDR) {
            if (!FlagManager::getInstance().fp16_client_target() || !isLayerFp16) {
                layerBrightnessNits *= layerFEState->currentHdrSdrRatio;
            }
        }

        state.dimmingRatio =
                std::clamp(layerBrightnessNits / getOutput().getState().displayBrightnessNits, 0.f,
                           1.f);