Merge "Provide dimming ratio instead of white point nits in composer"
diff --git a/graphics/composer/aidl/aidl_api/android.hardware.graphics.composer3/current/android/hardware/graphics/composer3/Luminance.aidl b/graphics/composer/aidl/aidl_api/android.hardware.graphics.composer3/current/android/hardware/graphics/composer3/LayerBrightness.aidl
similarity index 96%
rename from graphics/composer/aidl/aidl_api/android.hardware.graphics.composer3/current/android/hardware/graphics/composer3/Luminance.aidl
rename to graphics/composer/aidl/aidl_api/android.hardware.graphics.composer3/current/android/hardware/graphics/composer3/LayerBrightness.aidl
index adb49a8..a726cc1 100644
--- a/graphics/composer/aidl/aidl_api/android.hardware.graphics.composer3/current/android/hardware/graphics/composer3/Luminance.aidl
+++ b/graphics/composer/aidl/aidl_api/android.hardware.graphics.composer3/current/android/hardware/graphics/composer3/LayerBrightness.aidl
@@ -33,6 +33,6 @@
 
 package android.hardware.graphics.composer3;
 @VintfStability
-parcelable Luminance {
-  float nits;
+parcelable LayerBrightness {
+  float brightness;
 }
diff --git a/graphics/composer/aidl/aidl_api/android.hardware.graphics.composer3/current/android/hardware/graphics/composer3/LayerCommand.aidl b/graphics/composer/aidl/aidl_api/android.hardware.graphics.composer3/current/android/hardware/graphics/composer3/LayerCommand.aidl
index c1c0117..0c5fac9 100644
--- a/graphics/composer/aidl/aidl_api/android.hardware.graphics.composer3/current/android/hardware/graphics/composer3/LayerCommand.aidl
+++ b/graphics/composer/aidl/aidl_api/android.hardware.graphics.composer3/current/android/hardware/graphics/composer3/LayerCommand.aidl
@@ -50,7 +50,7 @@
   @nullable android.hardware.graphics.common.Rect[] visibleRegion;
   @nullable android.hardware.graphics.composer3.ZOrder z;
   @nullable float[] colorTransform;
-  @nullable android.hardware.graphics.composer3.Luminance whitePointNits;
+  @nullable android.hardware.graphics.composer3.LayerBrightness brightness;
   @nullable android.hardware.graphics.composer3.PerFrameMetadata[] perFrameMetadata;
   @nullable android.hardware.graphics.composer3.PerFrameMetadataBlob[] perFrameMetadataBlob;
   @nullable android.hardware.graphics.common.Rect[] blockingRegion;
diff --git a/graphics/composer/aidl/android/hardware/graphics/composer3/DisplayCommand.aidl b/graphics/composer/aidl/android/hardware/graphics/composer3/DisplayCommand.aidl
index f1ce1a7..b6df147 100644
--- a/graphics/composer/aidl/android/hardware/graphics/composer3/DisplayCommand.aidl
+++ b/graphics/composer/aidl/android/hardware/graphics/composer3/DisplayCommand.aidl
@@ -77,15 +77,7 @@
      * the display brightness, for example when internally switching the display between multiple
      * power modes to achieve higher luminance. In those cases, the underlying display panel's real
      * brightness may not be applied atomically; however, layer dimming when mixing HDR and SDR
-     * content must be synchronized.
-     *
-     * As an illustrative example: suppose two layers have white
-     * points of 200 nits and 1000 nits respectively, the old display luminance is 200 nits, and the
-     * new display luminance is 1000 nits. If the new display luminance takes two frames to apply,
-     * then: In the first frame, there must not be any relative dimming of layers (treat both layers
-     * as 200 nits as the maximum luminance of the display is 200 nits). In the second frame, there
-     * dimming should be applied to ensure that the first layer does not become perceptually
-     * brighter during the transition.
+     * content must be synchronized to ensure that there is no user-perceptable flicker.
      *
      * The display luminance must be updated by this command even if there is not pending validate
      * or present command.
diff --git a/graphics/composer/aidl/android/hardware/graphics/composer3/Luminance.aidl b/graphics/composer/aidl/android/hardware/graphics/composer3/LayerBrightness.aidl
similarity index 76%
rename from graphics/composer/aidl/android/hardware/graphics/composer3/Luminance.aidl
rename to graphics/composer/aidl/android/hardware/graphics/composer3/LayerBrightness.aidl
index 5b1c1b4..146e012 100644
--- a/graphics/composer/aidl/android/hardware/graphics/composer3/Luminance.aidl
+++ b/graphics/composer/aidl/android/hardware/graphics/composer3/LayerBrightness.aidl
@@ -17,10 +17,10 @@
 package android.hardware.graphics.composer3;
 
 @VintfStability
-parcelable Luminance {
+parcelable LayerBrightness {
     /**
-     * Photometric measure of luminous intensity per unit area of light.
-     * Units are nits, or cd/m^2.
+     * Brightness of the current layer, ranging from 0 to 1, where 0 is the minimum brightness of
+     * the display, and 1 is the current brightness of the display.
      */
-    float nits;
+    float brightness;
 }
diff --git a/graphics/composer/aidl/android/hardware/graphics/composer3/LayerCommand.aidl b/graphics/composer/aidl/android/hardware/graphics/composer3/LayerCommand.aidl
index 6f6894f..f3b67a9 100644
--- a/graphics/composer/aidl/android/hardware/graphics/composer3/LayerCommand.aidl
+++ b/graphics/composer/aidl/android/hardware/graphics/composer3/LayerCommand.aidl
@@ -22,7 +22,7 @@
 import android.hardware.graphics.common.Rect;
 import android.hardware.graphics.composer3.Buffer;
 import android.hardware.graphics.composer3.Color;
-import android.hardware.graphics.composer3.Luminance;
+import android.hardware.graphics.composer3.LayerBrightness;
 import android.hardware.graphics.composer3.ParcelableBlendMode;
 import android.hardware.graphics.composer3.ParcelableComposition;
 import android.hardware.graphics.composer3.ParcelableDataspace;
@@ -221,12 +221,12 @@
     @nullable float[] colorTransform;
 
     /**
-     * Sets the desired white point for the layer. This is intended to be used when presenting
-     * an SDR layer alongside HDR content. The HDR content will be presented at the display
-     * brightness in nits, and accordingly SDR content shall be dimmed to the desired white point
-     * provided.
+     * Sets the desired brightness for the layer. This is intended to be used for instance when
+     * presenting an SDR layer alongside HDR content. The HDR content will be presented at the
+     * display brightness in nits, and accordingly SDR content shall be dimmed according to the
+     * provided brightness ratio.
      */
-    @nullable Luminance whitePointNits;
+    @nullable LayerBrightness brightness;
 
     /**
      * Sets the PerFrameMetadata for the display. This metadata must be used
diff --git a/graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/VtsHalGraphicsComposer3_ReadbackTest.cpp b/graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/VtsHalGraphicsComposer3_ReadbackTest.cpp
index 92fa20c..686299a 100644
--- a/graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/VtsHalGraphicsComposer3_ReadbackTest.cpp
+++ b/graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/VtsHalGraphicsComposer3_ReadbackTest.cpp
@@ -960,7 +960,7 @@
     }
 }
 
-TEST_P(GraphicsCompositionTest, SetLayerWhitePointDims) {
+TEST_P(GraphicsCompositionTest, SetLayerBrightnessDims) {
     const auto& [status, capabilities] =
             mComposerClient->getDisplayCapabilities(getPrimaryDisplayId());
     ASSERT_TRUE(status.isOk());
@@ -1008,6 +1008,7 @@
         redLayer->setColor(RED);
         redLayer->setDisplayFrame(redRect);
         redLayer->setWhitePointNits(maxBrightnessNits);
+        redLayer->setBrightness(1.f);
 
         const auto dimmerRedLayer =
                 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
@@ -1017,6 +1018,7 @@
         // kick into GPU composition to apply dithering when the dimming ratio is high.
         static constexpr float kDimmingRatio = 0.9f;
         dimmerRedLayer->setWhitePointNits(maxBrightnessNits * kDimmingRatio);
+        dimmerRedLayer->setBrightness(kDimmingRatio);
 
         const std::vector<std::shared_ptr<TestLayer>> layers = {redLayer, dimmerRedLayer};
         std::vector<Color> expectedColors(
diff --git a/graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/VtsHalGraphicsComposer3_TargetTest.cpp b/graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/VtsHalGraphicsComposer3_TargetTest.cpp
index 17ec885..8d4bc11 100644
--- a/graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/VtsHalGraphicsComposer3_TargetTest.cpp
+++ b/graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/VtsHalGraphicsComposer3_TargetTest.cpp
@@ -1798,26 +1798,37 @@
     EXPECT_TRUE(mComposerClient->destroyLayer(getPrimaryDisplayId(), layer).isOk());
 }
 
-TEST_P(GraphicsComposerAidlCommandTest, SetLayerWhitePointNits) {
+TEST_P(GraphicsComposerAidlCommandTest, setLayerBrightness) {
     const auto& [layerStatus, layer] =
             mComposerClient->createLayer(getPrimaryDisplayId(), kBufferSlotCount);
-    EXPECT_TRUE(layerStatus.isOk());
 
-    mWriter.setLayerWhitePointNits(getPrimaryDisplayId(), layer, /*whitePointNits*/ 200.f);
+    mWriter.setLayerBrightness(getPrimaryDisplayId(), layer, 0.2f);
     execute();
     ASSERT_TRUE(mReader.takeErrors().empty());
 
-    mWriter.setLayerWhitePointNits(getPrimaryDisplayId(), layer, /*whitePointNits*/ 1000.f);
+    mWriter.setLayerBrightness(getPrimaryDisplayId(), layer, 1.f);
     execute();
     ASSERT_TRUE(mReader.takeErrors().empty());
 
-    mWriter.setLayerWhitePointNits(getPrimaryDisplayId(), layer, /*whitePointNits*/ 0.f);
+    mWriter.setLayerBrightness(getPrimaryDisplayId(), layer, 0.f);
     execute();
     ASSERT_TRUE(mReader.takeErrors().empty());
 
-    mWriter.setLayerWhitePointNits(getPrimaryDisplayId(), layer, /*whitePointNits*/ -1.f);
+    mWriter.setLayerBrightness(getPrimaryDisplayId(), layer, -1.f);
     execute();
-    ASSERT_TRUE(mReader.takeErrors().empty());
+    {
+        const auto errors = mReader.takeErrors();
+        ASSERT_EQ(1, errors.size());
+        EXPECT_EQ(IComposerClient::EX_BAD_PARAMETER, errors[0].errorCode);
+    }
+
+    mWriter.setLayerBrightness(getPrimaryDisplayId(), layer, std::nanf(""));
+    execute();
+    {
+        const auto errors = mReader.takeErrors();
+        ASSERT_EQ(1, errors.size());
+        EXPECT_EQ(IComposerClient::EX_BAD_PARAMETER, errors[0].errorCode);
+    }
 }
 
 TEST_P(GraphicsComposerAidlCommandTest, SetActiveConfigWithConstraints) {
diff --git a/graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/composer-vts/ReadbackVts.cpp b/graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/composer-vts/ReadbackVts.cpp
index ea432ef..553eec3 100644
--- a/graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/composer-vts/ReadbackVts.cpp
+++ b/graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/composer-vts/ReadbackVts.cpp
@@ -34,7 +34,7 @@
     writer.setLayerTransform(mDisplay, mLayer, mTransform);
     writer.setLayerPlaneAlpha(mDisplay, mLayer, mAlpha);
     writer.setLayerBlendMode(mDisplay, mLayer, mBlendMode);
-    writer.setLayerWhitePointNits(mDisplay, mLayer, mWhitePointNits);
+    writer.setLayerBrightness(mDisplay, mLayer, mBrightness);
 }
 
 std::string ReadbackHelper::getColorModeString(ColorMode mode) {
diff --git a/graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/composer-vts/include/ReadbackVts.h b/graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/composer-vts/include/ReadbackVts.h
index f9fab4f..ee9f0d5 100644
--- a/graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/composer-vts/include/ReadbackVts.h
+++ b/graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/composer-vts/include/ReadbackVts.h
@@ -67,6 +67,7 @@
     void setSourceCrop(FRect crop) { mSourceCrop = crop; }
     void setZOrder(uint32_t z) { mZOrder = z; }
     void setWhitePointNits(float whitePointNits) { mWhitePointNits = whitePointNits; }
+    void setBrightness(float brightness) { mBrightness = brightness; }
 
     void setSurfaceDamage(std::vector<Rect> surfaceDamage) {
         mSurfaceDamage = std::move(surfaceDamage);
@@ -84,12 +85,13 @@
 
     int64_t getLayer() const { return mLayer; }
 
-    float getWhitePointNits() const { return mWhitePointNits; }
+    float getBrightness() const { return mBrightness; }
 
   protected:
     int64_t mDisplay;
     int64_t mLayer;
     Rect mDisplayFrame = {0, 0, 0, 0};
+    float mBrightness = 1.f;
     float mWhitePointNits = -1.f;
     std::vector<Rect> mSurfaceDamage;
     Transform mTransform = static_cast<Transform>(0);
diff --git a/graphics/composer/aidl/include/android/hardware/graphics/composer3/ComposerClientWriter.h b/graphics/composer/aidl/include/android/hardware/graphics/composer3/ComposerClientWriter.h
index a04b982..ae17c51 100644
--- a/graphics/composer/aidl/include/android/hardware/graphics/composer3/ComposerClientWriter.h
+++ b/graphics/composer/aidl/include/android/hardware/graphics/composer3/ComposerClientWriter.h
@@ -30,7 +30,7 @@
 #include <aidl/android/hardware/graphics/composer3/Color.h>
 #include <aidl/android/hardware/graphics/composer3/Composition.h>
 #include <aidl/android/hardware/graphics/composer3/DisplayBrightness.h>
-#include <aidl/android/hardware/graphics/composer3/Luminance.h>
+#include <aidl/android/hardware/graphics/composer3/LayerBrightness.h>
 #include <aidl/android/hardware/graphics/composer3/PerFrameMetadata.h>
 #include <aidl/android/hardware/graphics/composer3/PerFrameMetadataBlob.h>
 
@@ -209,8 +209,9 @@
                 .perFrameMetadataBlob.emplace(metadata.begin(), metadata.end());
     }
 
-    void setLayerWhitePointNits(int64_t display, int64_t layer, float whitePointNits) {
-        getLayerCommand(display, layer).whitePointNits.emplace(Luminance{.nits = whitePointNits});
+    void setLayerBrightness(int64_t display, int64_t layer, float brightness) {
+        getLayerCommand(display, layer)
+                .brightness.emplace(LayerBrightness{.brightness = brightness});
     }
 
     void setLayerBlockingRegion(int64_t display, int64_t layer, const std::vector<Rect>& blocking) {