Only scale SDR luminance by content max luminance for tonemapping
If color conversion is SDR->SDR, then scale luminance only by the
display luminance.
The use-case is for applying a color transform, which was defined to
occcur in linear space. Since uniform generation for tonemapping is (for
now) dataspace-agnostic, this means that scaling by the content
luminance should not be used since a tone-mapping operator may override
the one that is provided by applications.
Bug: 200310159
Test: builds, boots
Test: librenderengine_test
Change-Id: I2cc5860b6df064664c5e462674df20b589eae291
diff --git a/libs/renderengine/skia/filters/LinearEffect.cpp b/libs/renderengine/skia/filters/LinearEffect.cpp
index 53136e4..c3a5a60 100644
--- a/libs/renderengine/skia/filters/LinearEffect.cpp
+++ b/libs/renderengine/skia/filters/LinearEffect.cpp
@@ -114,7 +114,8 @@
}
// Conversion from relative light to absolute light (maps from [0, 1] to [0, maxNits])
-static void generateLuminanceScalesForOOTF(ui::Dataspace inputDataspace, SkString& shader) {
+static void generateLuminanceScalesForOOTF(ui::Dataspace inputDataspace,
+ ui::Dataspace outputDataspace, SkString& shader) {
switch (inputDataspace & HAL_DATASPACE_TRANSFER_MASK) {
case HAL_DATASPACE_TRANSFER_ST2084:
shader.append(R"(
@@ -131,12 +132,26 @@
)");
break;
default:
- shader.append(R"(
- float3 ScaleLuminance(float3 xyz) {
- return xyz * in_libtonemap_inputMaxLuminance;
- }
- )");
- break;
+ switch (outputDataspace & HAL_DATASPACE_TRANSFER_MASK) {
+ case HAL_DATASPACE_TRANSFER_ST2084:
+ case HAL_DATASPACE_TRANSFER_HLG:
+ // SDR -> HDR tonemap
+ shader.append(R"(
+ float3 ScaleLuminance(float3 xyz) {
+ return xyz * in_libtonemap_inputMaxLuminance;
+ }
+ )");
+ break;
+ default:
+ // Input and output are both SDR, so no tone-mapping is expected so
+ // no-op the luminance normalization.
+ shader.append(R"(
+ float3 ScaleLuminance(float3 xyz) {
+ return xyz * in_libtonemap_displayMaxLuminance;
+ }
+ )");
+ break;
+ }
}
}
@@ -174,7 +189,7 @@
toAidlDataspace(outputDataspace))
.c_str());
- generateLuminanceScalesForOOTF(inputDataspace, shader);
+ generateLuminanceScalesForOOTF(inputDataspace, outputDataspace, shader);
generateLuminanceNormalizationForOOTF(outputDataspace, shader);
shader.append(R"(