Skip to content

Commit 86a707a

Browse files
Treehugger RobotAndroid (Google) Code Review
authored andcommitted
Merge "Limit HLG to 4.926x SDR" into main
2 parents c6102c0 + 8face53 commit 86a707a

6 files changed

Lines changed: 56 additions & 5 deletions

File tree

libs/ui/include_types/ui/HdrRenderTypeUtils.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,24 @@ inline HdrRenderType getHdrRenderType(ui::Dataspace dataspace,
6161
return HdrRenderType::SDR;
6262
}
6363

64-
} // namespace android
64+
/**
65+
* Returns the maximum headroom allowed for this content under "idealized"
66+
* display conditions (low surround luminance, high-enough display brightness).
67+
*
68+
* TODO: take into account hdr metadata, but square it with the fact that some
69+
* HLG content has CTA.861-3 metadata
70+
*/
71+
inline float getIdealizedMaxHeadroom(ui::Dataspace dataspace) {
72+
const auto transfer = dataspace & HAL_DATASPACE_TRANSFER_MASK;
73+
74+
switch (transfer) {
75+
case HAL_DATASPACE_TRANSFER_ST2084:
76+
return 10000.0f / 203.0f;
77+
case HAL_DATASPACE_TRANSFER_HLG:
78+
return 1000.0f / 203.0f;
79+
default:
80+
return 1.0f;
81+
}
82+
}
83+
84+
} // namespace android

services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <ui/FloatRect.h>
2727
#include <ui/HdrRenderTypeUtils.h>
2828
#include <cstdint>
29+
#include <limits>
2930
#include "system/graphics-base-v1.0.h"
3031

3132
#include <com_android_graphics_libgui_flags.h>
@@ -398,11 +399,22 @@ void OutputLayer::updateCompositionState(
398399
// For hdr content, treat the white point as the display brightness - HDR content should not be
399400
// boosted or dimmed.
400401
// If the layer explicitly requests to disable dimming, then don't dim either.
401-
if (hdrRenderType == HdrRenderType::GENERIC_HDR ||
402-
getOutput().getState().displayBrightnessNits == getOutput().getState().sdrWhitePointNits ||
403-
getOutput().getState().displayBrightnessNits == 0.f || !layerFEState->dimmingEnabled) {
402+
if (getOutput().getState().displayBrightnessNits == getOutput().getState().sdrWhitePointNits ||
403+
getOutput().getState().displayBrightnessNits <= 0.f || !layerFEState->dimmingEnabled) {
404404
state.dimmingRatio = 1.f;
405405
state.whitePointNits = getOutput().getState().displayBrightnessNits;
406+
} else if (hdrRenderType == HdrRenderType::GENERIC_HDR) {
407+
float deviceHeadroom = getOutput().getState().displayBrightnessNits /
408+
getOutput().getState().sdrWhitePointNits;
409+
float idealizedMaxHeadroom = deviceHeadroom;
410+
411+
if (FlagManager::getInstance().begone_bright_hlg()) {
412+
idealizedMaxHeadroom =
413+
std::min(idealizedMaxHeadroom, getIdealizedMaxHeadroom(state.dataspace));
414+
}
415+
416+
state.dimmingRatio = std::min(idealizedMaxHeadroom / deviceHeadroom, 1.0f);
417+
state.whitePointNits = getOutput().getState().displayBrightnessNits * state.dimmingRatio;
406418
} else {
407419
float layerBrightnessNits = getOutput().getState().sdrWhitePointNits;
408420
// RANGE_EXTENDED can "self-promote" to HDR, but is still rendered for a particular

services/surfaceflinger/SurfaceFlinger.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3201,7 +3201,15 @@ void SurfaceFlinger::onCompositionPresented(PhysicalDisplayId pacesetterId,
32013201
snapshot.desiredHdrSdrRatio < 1.f
32023202
? std::numeric_limits<float>::infinity()
32033203
: snapshot.desiredHdrSdrRatio;
3204-
info.mergeDesiredRatio(desiredHdrSdrRatio);
3204+
3205+
float desiredRatio = desiredHdrSdrRatio;
3206+
if (FlagManager::getInstance().begone_bright_hlg() &&
3207+
desiredHdrSdrRatio ==
3208+
std::numeric_limits<float>::infinity()) {
3209+
desiredRatio = getIdealizedMaxHeadroom(snapshot.dataspace);
3210+
}
3211+
3212+
info.mergeDesiredRatio(desiredRatio);
32053213
info.numberOfHdrLayers++;
32063214
const auto displayFrame = outputLayer->getState().displayFrame;
32073215
const int32_t area =

services/surfaceflinger/common/FlagManager.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ void FlagManager::dump(std::string& result) const {
160160
DUMP_READ_ONLY_FLAG(connected_display_hdr);
161161
DUMP_READ_ONLY_FLAG(deprecate_frame_tracker);
162162
DUMP_READ_ONLY_FLAG(skip_invisible_windows_in_input);
163+
DUMP_READ_ONLY_FLAG(begone_bright_hlg);
163164

164165
#undef DUMP_READ_ONLY_FLAG
165166
#undef DUMP_SERVER_FLAG
@@ -268,6 +269,7 @@ FLAG_MANAGER_READ_ONLY_FLAG(display_config_error_hal, "");
268269
FLAG_MANAGER_READ_ONLY_FLAG(connected_display_hdr, "");
269270
FLAG_MANAGER_READ_ONLY_FLAG(deprecate_frame_tracker, "");
270271
FLAG_MANAGER_READ_ONLY_FLAG(skip_invisible_windows_in_input, "");
272+
FLAG_MANAGER_READ_ONLY_FLAG(begone_bright_hlg, "debug.sf.begone_bright_hlg");
271273

272274
/// Trunk stable server flags ///
273275
FLAG_MANAGER_SERVER_FLAG(refresh_rate_overlay_on_external_display, "")

services/surfaceflinger/common/include/common/FlagManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class FlagManager {
9898
bool connected_display_hdr() const;
9999
bool deprecate_frame_tracker() const;
100100
bool skip_invisible_windows_in_input() const;
101+
bool begone_bright_hlg() const;
101102

102103
protected:
103104
// overridden for unit tests

services/surfaceflinger/surfaceflinger_flags_new.aconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ flag {
3434
is_fixed_read_only: true
3535
} # arr_surfacecontrol_setframerate_api
3636

37+
flag {
38+
name: "begone_bright_hlg"
39+
namespace: "core_graphics"
40+
description: "Caps HLG brightness relative to SDR"
41+
bug: "362510107"
42+
is_fixed_read_only: true
43+
} # begone_bright_hlg
44+
3745
flag {
3846
name: "ce_fence_promise"
3947
namespace: "window_surfaces"

0 commit comments

Comments
 (0)