surfaceflinger: add BT2020_PQ support to RenderEngine

Add Key::Y410_BT2020_ON which performs Y410/BT2020 YUV -> RGB
conversion.

Add Key::{INPUT,OUTPUT}_TF_ST2084 which performs ST2084 EOTF and
OETF conversions.

Add Key::TONE_MAP_ON which performs tone-mapping.

Flip proper bits on when the source buffer has BT2020_PQ as its
dataspace.  That means,

  1. convert YUV to RGB
  2. apply ST 2084 EOTF
  3. apply tone-mapping
  4. convert to DisplayP3
  5. apply relative rendering intent (i.e., clamp)
  6. finally apply sRGB OETF

We still use hardcoded parameters rather than the ones from HDR
metadata.  It is also likely that we will need to switch to a LUT
for better perf.

Test: manual
Change-Id: I53556a2acfc34ef55e88c5b139000be94072dd3e
diff --git a/services/surfaceflinger/RenderEngine/GLES20RenderEngine.cpp b/services/surfaceflinger/RenderEngine/GLES20RenderEngine.cpp
index 745929d..323cec7 100644
--- a/services/surfaceflinger/RenderEngine/GLES20RenderEngine.cpp
+++ b/services/surfaceflinger/RenderEngine/GLES20RenderEngine.cpp
@@ -132,6 +132,10 @@
         // Display-P3 only.
         mSrgbToDisplayP3 = mat4(
                 ColorSpaceConnector(ColorSpace::sRGB(), ColorSpace::DisplayP3()).getTransform());
+
+        // Compute BT2020 to DisplayP3 color transform
+        mBt2020ToDisplayP3 = mat4(
+                ColorSpaceConnector(ColorSpace::BT2020(), ColorSpace::DisplayP3()).getTransform());
     }
 }
 
@@ -229,6 +233,10 @@
     mDataSpace = source;
 }
 
+void GLES20RenderEngine::setSourceY410BT2020(bool enable) {
+    mState.setY410BT2020(enable);
+}
+
 void GLES20RenderEngine::setWideColor(bool hasWideColor) {
     ALOGV("setWideColor: %s", hasWideColor ? "true" : "false");
     mDisplayHasWideColor = hasWideColor;
@@ -322,6 +330,12 @@
             case HAL_DATASPACE_DISPLAY_P3:
                 // input matches output
                 break;
+            case HAL_DATASPACE_BT2020_PQ:
+                wideColorState.setColorMatrix(mState.getColorMatrix() * mBt2020ToDisplayP3);
+                wideColorState.setInputTransferFunction(Description::TransferFunction::ST2084);
+                wideColorState.setOutputTransferFunction(Description::TransferFunction::SRGB);
+                wideColorState.enableToneMapping(true);
+                break;
             default:
                 wideColorState.setColorMatrix(mState.getColorMatrix() * mSrgbToDisplayP3);
                 wideColorState.setInputTransferFunction(Description::TransferFunction::SRGB);