Send dimming ratio to composer instead of white point nits

* Send the dimming ratio over to composer as the HWC api is changing to
  not expose the notion of nits to composer, as the white point nits are
  part of logical SF state that does not map as nicely to display
  hardware
* Fixes an issue where scheduling a recomposite for a frame when
  brightness changes is contingent on the presence of HDR layers, which
  is not valid when an HDR layer exits the scene, but DisplayManager
  animates the display brightness down to the SDR white point.

Bug: 217961164
Test: builds, boots
Test: HDR test videos on youtube
Change-Id: Icc07b00f60859bbd3ee078cd2bb793eda42e7781
diff --git a/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp b/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp
index 4ccf11f..3e983f3 100644
--- a/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp
+++ b/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp
@@ -324,9 +324,14 @@
 
     // For hdr content, treat the white point as the display brightness - HDR content should not be
     // boosted or dimmed.
-    if (isHdrDataspace(state.dataspace)) {
+    if (isHdrDataspace(state.dataspace) ||
+        getOutput().getState().displayBrightnessNits == getOutput().getState().sdrWhitePointNits) {
+        state.dimmingRatio = 1.f;
         state.whitePointNits = getOutput().getState().displayBrightnessNits;
     } else {
+        state.dimmingRatio = std::clamp(getOutput().getState().sdrWhitePointNits /
+                                                getOutput().getState().displayBrightnessNits,
+                                        0.f, 1.f);
         state.whitePointNits = getOutput().getState().sdrWhitePointNits;
     }
 
@@ -502,13 +507,12 @@
     }
 
     // Don't dim cached layers
-    const auto whitePointNits = outputDependentState.overrideInfo.buffer
-            ? getOutput().getState().displayBrightnessNits
-            : outputDependentState.whitePointNits;
+    const auto dimmingRatio =
+            outputDependentState.overrideInfo.buffer ? 1.f : outputDependentState.dimmingRatio;
 
-    if (auto error = hwcLayer->setWhitePointNits(whitePointNits); error != hal::Error::NONE) {
-        ALOGE("[%s] Failed to set white point %f: %s (%d)", getLayerFE().getDebugName(),
-              whitePointNits, to_string(error).c_str(), static_cast<int32_t>(error));
+    if (auto error = hwcLayer->setBrightness(dimmingRatio); error != hal::Error::NONE) {
+        ALOGE("[%s] Failed to set brightness %f: %s (%d)", getLayerFE().getDebugName(),
+              dimmingRatio, to_string(error).c_str(), static_cast<int32_t>(error));
     }
 }