@@ -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