summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChia-I Wu <olv@google.com>2018-05-25 21:53:21 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2018-05-25 21:53:21 +0000
commitca175ee15a529cca0eb2bc8372e552d4ad255fc0 (patch)
treea6b0e8365aa1c4c90b78ed7e24658865eaacc5d9
parent31419e7ac873051e9adbd89fe8c3d085997f28a8 (diff)
parent9a1b65566d8cfcd46b56c26ecda307d0266ad26a (diff)
downloadnative-ca175ee15a529cca0eb2bc8372e552d4ad255fc0.tar.gz
Merge "[RenderEngine] Add inverse tone mapper." into pi-dev
-rw-r--r--services/surfaceflinger/RenderEngine/ProgramCache.cpp41
1 files changed, 38 insertions, 3 deletions
diff --git a/services/surfaceflinger/RenderEngine/ProgramCache.cpp b/services/surfaceflinger/RenderEngine/ProgramCache.cpp
index 2808a1a912..5b61db9fbd 100644
--- a/services/surfaceflinger/RenderEngine/ProgramCache.cpp
+++ b/services/surfaceflinger/RenderEngine/ProgramCache.cpp
@@ -345,11 +345,46 @@ void ProgramCache::generateToneMappingProcess(Formatter& fs, const Key& needs) {
}
break;
default:
- // TODO(73825729) We need to revert the tone mapping in
- // hardware composer properly.
+ // inverse tone map; the output luminance can be up to maxOutLumi.
fs << R"__SHADER__(
highp vec3 ToneMap(highp vec3 color) {
- return color;
+ const float maxOutLumi = 3000.0;
+
+ const float x0 = 5.0;
+ const float y0 = 2.5;
+ float x1 = displayMaxLuminance * 0.7;
+ float y1 = maxOutLumi * 0.15;
+ float x2 = displayMaxLuminance * 0.9;
+ float y2 = maxOutLumi * 0.45;
+ float x3 = displayMaxLuminance;
+ float y3 = maxOutLumi;
+
+ float c1 = y1 / 3.0;
+ float c2 = y2 / 2.0;
+ float c3 = y3 / 1.5;
+
+ float nits = color.y;
+
+ float scale;
+ if (nits <= x0) {
+ // scale [0.0, x0] to [0.0, y0] linearly
+ const float slope = y0 / x0;
+ nits *= slope;
+ } else if (nits <= x1) {
+ // scale [x0, x1] to [y0, y1] using a curve
+ float t = (nits - x0) / (x1 - x0);
+ nits = (1.0 - t) * (1.0 - t) * y0 + 2.0 * (1.0 - t) * t * c1 + t * t * y1;
+ } else if (nits <= x2) {
+ // scale [x1, x2] to [y1, y2] using a curve
+ float t = (nits - x1) / (x2 - x1);
+ nits = (1.0 - t) * (1.0 - t) * y1 + 2.0 * (1.0 - t) * t * c2 + t * t * y2;
+ } else {
+ // scale [x2, x3] to [y2, y3] using a curve
+ float t = (nits - x2) / (x3 - x2);
+ nits = (1.0 - t) * (1.0 - t) * y2 + 2.0 * (1.0 - t) * t * c3 + t * t * y3;
+ }
+
+ return color * (nits / max(1e-6, color.y));
}
)__SHADER__";
break;