Adjustments to composer apis for HDR:
1. Add setDisplayBrightness as a display command, so that it may be
set atomically with composition updates for that display.
2. Adjust tests to set display brightness using display commands.
The setDisplayBrightness api on IComposer should be deprecated. It will
be removed in a follow-up patch.
Bug: 210151839
Test: builds
Change-Id: I2e4348e1d7f799d1744390afbb9bd206054eb933
diff --git a/graphics/composer/aidl/aidl_api/android.hardware.graphics.composer3/current/android/hardware/graphics/composer3/DisplayBrightness.aidl b/graphics/composer/aidl/aidl_api/android.hardware.graphics.composer3/current/android/hardware/graphics/composer3/DisplayBrightness.aidl
new file mode 100644
index 0000000..be623df
--- /dev/null
+++ b/graphics/composer/aidl/aidl_api/android.hardware.graphics.composer3/current/android/hardware/graphics/composer3/DisplayBrightness.aidl
@@ -0,0 +1,38 @@
+/**
+ * Copyright 2021, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+///////////////////////////////////////////////////////////////////////////////
+// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. //
+///////////////////////////////////////////////////////////////////////////////
+
+// This file is a snapshot of an AIDL file. Do not edit it manually. There are
+// two cases:
+// 1). this is a frozen version file - do not edit this in any case.
+// 2). this is a 'current' file. If you make a backwards compatible change to
+// the interface (from the latest frozen version), the build system will
+// prompt you to update this file with `m <name>-update-api`.
+//
+// You must not make a backward incompatible change to any AIDL file built
+// with the aidl_interface module type with versions property set. The module
+// type is used to build AIDL files in a way that they can be used across
+// independently updatable components of the system. If a device is shipped
+// with such a backward incompatible change, it has a high risk of breaking
+// later when a module using the interface is updated, e.g., Mainline modules.
+
+package android.hardware.graphics.composer3;
+@VintfStability
+parcelable DisplayBrightness {
+ float brightness;
+}
diff --git a/graphics/composer/aidl/aidl_api/android.hardware.graphics.composer3/current/android/hardware/graphics/composer3/DisplayCommand.aidl b/graphics/composer/aidl/aidl_api/android.hardware.graphics.composer3/current/android/hardware/graphics/composer3/DisplayCommand.aidl
index 3382633..662240e 100644
--- a/graphics/composer/aidl/aidl_api/android.hardware.graphics.composer3/current/android/hardware/graphics/composer3/DisplayCommand.aidl
+++ b/graphics/composer/aidl/aidl_api/android.hardware.graphics.composer3/current/android/hardware/graphics/composer3/DisplayCommand.aidl
@@ -37,6 +37,7 @@
long display;
android.hardware.graphics.composer3.LayerCommand[] layers;
@nullable float[] colorTransformMatrix;
+ @nullable android.hardware.graphics.composer3.DisplayBrightness brightness;
@nullable android.hardware.graphics.composer3.ClientTarget clientTarget;
@nullable android.hardware.graphics.composer3.Buffer virtualDisplayOutputBuffer;
@nullable android.hardware.graphics.composer3.ClockMonotonicTimestamp expectedPresentTime;
diff --git a/graphics/composer/aidl/android/hardware/graphics/composer3/DisplayBrightness.aidl b/graphics/composer/aidl/android/hardware/graphics/composer3/DisplayBrightness.aidl
new file mode 100644
index 0000000..f66b235
--- /dev/null
+++ b/graphics/composer/aidl/android/hardware/graphics/composer3/DisplayBrightness.aidl
@@ -0,0 +1,26 @@
+/**
+ * Copyright 2021, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.hardware.graphics.composer3;
+
+@VintfStability
+parcelable DisplayBrightness {
+ /**
+ * A number between 0.0f (minimum brightness) and 1.0f (maximum brightness), a negative value to
+ * turn the backlight off.
+ */
+ float brightness;
+}
diff --git a/graphics/composer/aidl/android/hardware/graphics/composer3/DisplayCommand.aidl b/graphics/composer/aidl/android/hardware/graphics/composer3/DisplayCommand.aidl
index 18461ad..f1ce1a7 100644
--- a/graphics/composer/aidl/android/hardware/graphics/composer3/DisplayCommand.aidl
+++ b/graphics/composer/aidl/android/hardware/graphics/composer3/DisplayCommand.aidl
@@ -19,6 +19,7 @@
import android.hardware.graphics.composer3.Buffer;
import android.hardware.graphics.composer3.ClientTarget;
import android.hardware.graphics.composer3.ClockMonotonicTimestamp;
+import android.hardware.graphics.composer3.DisplayBrightness;
import android.hardware.graphics.composer3.LayerCommand;
@VintfStability
@@ -69,6 +70,29 @@
@nullable float[] colorTransformMatrix;
/**
+ * Sets the desired brightness of the display.
+ *
+ * Ideally, the brightness of the display will take effect within this frame so that it can be
+ * aligned with color transforms. Some display architectures may take multiple frames to apply
+ * 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.
+ *
+ * The display luminance must be updated by this command even if there is not pending validate
+ * or present command.
+ */
+ @nullable DisplayBrightness brightness;
+
+ /**
* Sets the buffer handle which will receive the output of client
* composition. Layers marked as Composition.CLIENT must be composited
* into this buffer prior to the call to PRESENT_DISPLAY, and layers not
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 4dbe191..a591aaa 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
@@ -568,37 +568,6 @@
}
}
-/*
- * Test that if brightness operations are supported, setDisplayBrightness works as expected.
- */
-TEST_P(GraphicsComposerAidlTest, setDisplayBrightness) {
- std::vector<DisplayCapability> capabilities;
- auto error = mComposerClient->getDisplayCapabilities(mPrimaryDisplay, &capabilities);
- ASSERT_TRUE(error.isOk());
- bool brightnessSupport = std::find(capabilities.begin(), capabilities.end(),
- DisplayCapability::BRIGHTNESS) != capabilities.end();
- if (!brightnessSupport) {
- EXPECT_EQ(mComposerClient->setDisplayBrightness(mPrimaryDisplay, 0.5f)
- .getServiceSpecificError(),
- IComposerClient::EX_UNSUPPORTED);
- GTEST_SUCCEED() << "Brightness operations are not supported";
- return;
- }
-
- EXPECT_TRUE(mComposerClient->setDisplayBrightness(mPrimaryDisplay, 0.0f).isOk());
- EXPECT_TRUE(mComposerClient->setDisplayBrightness(mPrimaryDisplay, 0.5f).isOk());
- EXPECT_TRUE(mComposerClient->setDisplayBrightness(mPrimaryDisplay, 1.0f).isOk());
- EXPECT_TRUE(mComposerClient->setDisplayBrightness(mPrimaryDisplay, -1.0f).isOk());
-
- error = mComposerClient->setDisplayBrightness(mPrimaryDisplay, +2.0f);
- EXPECT_FALSE(error.isOk());
- EXPECT_EQ(error.getServiceSpecificError(), IComposerClient::EX_BAD_PARAMETER);
-
- error = mComposerClient->setDisplayBrightness(mPrimaryDisplay, -2.0f);
- EXPECT_FALSE(error.isOk());
- EXPECT_EQ(error.getServiceSpecificError(), IComposerClient::EX_BAD_PARAMETER);
-}
-
TEST_P(GraphicsComposerAidlTest, getDisplayConnectionType) {
DisplayConnectionType type;
EXPECT_FALSE(mComposerClient->getDisplayConnectionType(mInvalidDisplayId, &type).isOk());
@@ -1494,6 +1463,55 @@
}
}
+TEST_P(GraphicsComposerAidlCommandTest, SetDisplayBrightness) {
+ std::vector<DisplayCapability> capabilities;
+ auto error = mComposerClient->getDisplayCapabilities(mPrimaryDisplay, &capabilities);
+ ASSERT_TRUE(error.isOk());
+ bool brightnessSupport = std::find(capabilities.begin(), capabilities.end(),
+ DisplayCapability::BRIGHTNESS) != capabilities.end();
+ if (!brightnessSupport) {
+ mWriter.setDisplayBrightness(mPrimaryDisplay, 0.5f);
+ execute();
+ const auto errors = mReader.takeErrors();
+ EXPECT_EQ(1, errors.size());
+ EXPECT_EQ(EX_UNSUPPORTED_OPERATION, errors[0].errorCode);
+ GTEST_SUCCEED() << "SetDisplayBrightness is not supported";
+ return;
+ }
+
+ mWriter.setDisplayBrightness(mPrimaryDisplay, 0.0f);
+ execute();
+ EXPECT_TRUE(mReader.takeErrors().empty());
+
+ mWriter.setDisplayBrightness(mPrimaryDisplay, 0.5f);
+ execute();
+ EXPECT_TRUE(mReader.takeErrors().empty());
+
+ mWriter.setDisplayBrightness(mPrimaryDisplay, 1.0f);
+ execute();
+ EXPECT_TRUE(mReader.takeErrors().empty());
+
+ mWriter.setDisplayBrightness(mPrimaryDisplay, -1.0f);
+ execute();
+ EXPECT_TRUE(mReader.takeErrors().empty());
+
+ mWriter.setDisplayBrightness(mPrimaryDisplay, 2.0f);
+ execute();
+ {
+ const auto errors = mReader.takeErrors();
+ EXPECT_EQ(1, errors.size());
+ EXPECT_EQ(IComposerClient::EX_BAD_PARAMETER, errors[0].errorCode);
+ }
+
+ mWriter.setDisplayBrightness(mPrimaryDisplay, -2.0f);
+ execute();
+ {
+ const auto errors = mReader.takeErrors();
+ EXPECT_EQ(1, errors.size());
+ EXPECT_EQ(IComposerClient::EX_BAD_PARAMETER, errors[0].errorCode);
+ }
+}
+
TEST_P(GraphicsComposerAidlCommandTest, SET_CLIENT_TARGET) {
EXPECT_TRUE(
mComposerClient->setClientTargetSlotCount(mPrimaryDisplay, kBufferSlotCount).isOk());
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 16d63e5..b202b34 100644
--- a/graphics/composer/aidl/include/android/hardware/graphics/composer3/ComposerClientWriter.h
+++ b/graphics/composer/aidl/include/android/hardware/graphics/composer3/ComposerClientWriter.h
@@ -29,9 +29,11 @@
#include <aidl/android/hardware/graphics/common/BlendMode.h>
#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/FloatColor.h>
#include <aidl/android/hardware/graphics/composer3/PerFrameMetadata.h>
#include <aidl/android/hardware/graphics/composer3/PerFrameMetadataBlob.h>
+#include <aidl/android/hardware/graphics/composer3/WhitePointNits.h>
#include <aidl/android/hardware/graphics/composer3/DisplayCommand.h>
@@ -79,6 +81,10 @@
getDisplayCommand(display).colorTransformMatrix.emplace(std::move(matVec));
}
+ void setDisplayBrightness(int64_t display, float brightness) {
+ getDisplayCommand(display).brightness.emplace(DisplayBrightness{.brightness = brightness});
+ }
+
void setClientTarget(int64_t display, uint32_t slot, const native_handle_t* target,
int acquireFence, Dataspace dataspace, const std::vector<Rect>& damage) {
ClientTarget clientTargetCommand;