Skip to content

Commit 9dbf512

Browse files
AMouriAndroid (Google) Code Review
authored andcommitted
Merge "Set right dimmingRatio for fp16 input layers without metadata" into main
2 parents 18a80f9 + c282e18 commit 9dbf512

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

libs/ui/include_types/ui/HdrRenderTypeUtils.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ enum class HdrRenderType {
3636
*/
3737
inline HdrRenderType getHdrRenderType(ui::Dataspace dataspace,
3838
std::optional<ui::PixelFormat> pixelFormat,
39-
float hdrSdrRatio = 1.f) {
39+
float hdrSdrRatio = 1.f, bool hasHdrMetadata = false) {
4040
const auto transfer = dataspace & HAL_DATASPACE_TRANSFER_MASK;
4141
const auto range = dataspace & HAL_DATASPACE_RANGE_MASK;
4242

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

5151
if ((dataspace == BT2020_LINEAR_EXT || dataspace == ui::Dataspace::V0_SCRGB) &&
52-
pixelFormat.has_value() && pixelFormat.value() == ui::PixelFormat::RGBA_FP16) {
52+
pixelFormat.has_value() && pixelFormat.value() == ui::PixelFormat::RGBA_FP16 &&
53+
hasHdrMetadata) {
5354
return HdrRenderType::GENERIC_HDR;
5455
}
5556

services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,11 @@ void OutputLayer::updateCompositionState(
369369
layerFEState->buffer->getPixelFormat()))
370370
: std::nullopt;
371371

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

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

395398
// re-get HdrRenderType after the dataspace gets changed.
396-
hdrRenderType =
397-
getHdrRenderType(state.dataspace, pixelFormat, layerFEState->desiredHdrSdrRatio);
399+
hdrRenderType = getHdrRenderType(state.dataspace, pixelFormat, layerFEState->desiredHdrSdrRatio,
400+
hasHdrMetadata);
398401

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

0 commit comments

Comments
 (0)