From 38565ccd51beaa1ac0dc55cd46274572c323651b Mon Sep 17 00:00:00 2001 From: Manali Bhutiyani Date: Sat, 11 Nov 2023 06:16:24 +0000 Subject: [PATCH] [hwc-batching] AIDL changes for HWC command batching support. This CL adds the new aidl/apis for HWC command batching feature. Bug: 290685621 Test: atest VtsHalGraphicsComposer3_TargetTest atest PerInstance/GraphicsComposerAidlBatchedCommandTest Change-Id: I9e8a8afefb03e04a4cd4d8db36d72e29d30e975f --- .../graphics/composer3/LayerCommand.aidl | 2 + .../LayerLifecycleBatchCommandType.aidl | 40 ++++++++++++ .../graphics/composer3/LayerCommand.aidl | 14 +++++ .../LayerLifecycleBatchCommandType.aidl | 39 ++++++++++++ .../graphics/composer3/ComposerClientWriter.h | 10 +++ .../VtsHalGraphicsComposer3_TargetTest.cpp | 63 +++++++++++++++++++ 6 files changed, 168 insertions(+) create mode 100644 graphics/composer/aidl/aidl_api/android.hardware.graphics.composer3/current/android/hardware/graphics/composer3/LayerLifecycleBatchCommandType.aidl create mode 100644 graphics/composer/aidl/android/hardware/graphics/composer3/LayerLifecycleBatchCommandType.aidl 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 6d32218af1..87c8c18443 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 @@ -55,4 +55,6 @@ parcelable LayerCommand { @nullable android.hardware.graphics.composer3.PerFrameMetadataBlob[] perFrameMetadataBlob; @nullable android.hardware.graphics.common.Rect[] blockingRegion; @nullable int[] bufferSlotsToClear; + android.hardware.graphics.composer3.LayerLifecycleBatchCommandType layerLifecycleBatchCommandType; + int newBufferSlotCount; } diff --git a/graphics/composer/aidl/aidl_api/android.hardware.graphics.composer3/current/android/hardware/graphics/composer3/LayerLifecycleBatchCommandType.aidl b/graphics/composer/aidl/aidl_api/android.hardware.graphics.composer3/current/android/hardware/graphics/composer3/LayerLifecycleBatchCommandType.aidl new file mode 100644 index 0000000000..ac78cd51f9 --- /dev/null +++ b/graphics/composer/aidl/aidl_api/android.hardware.graphics.composer3/current/android/hardware/graphics/composer3/LayerLifecycleBatchCommandType.aidl @@ -0,0 +1,40 @@ +/** + * Copyright (c) 2023, 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 -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; +@Backing(type="int") @VintfStability +enum LayerLifecycleBatchCommandType { + MODIFY = 0, + CREATE = 1, + DESTROY = 2, +} diff --git a/graphics/composer/aidl/android/hardware/graphics/composer3/LayerCommand.aidl b/graphics/composer/aidl/android/hardware/graphics/composer3/LayerCommand.aidl index fd50be9cfe..e961c48700 100644 --- a/graphics/composer/aidl/android/hardware/graphics/composer3/LayerCommand.aidl +++ b/graphics/composer/aidl/android/hardware/graphics/composer3/LayerCommand.aidl @@ -23,6 +23,7 @@ import android.hardware.graphics.common.Rect; import android.hardware.graphics.composer3.Buffer; import android.hardware.graphics.composer3.Color; import android.hardware.graphics.composer3.LayerBrightness; +import android.hardware.graphics.composer3.LayerLifecycleBatchCommandType; import android.hardware.graphics.composer3.ParcelableBlendMode; import android.hardware.graphics.composer3.ParcelableComposition; import android.hardware.graphics.composer3.ParcelableDataspace; @@ -265,4 +266,17 @@ parcelable LayerCommand { * be freed. */ @nullable int[] bufferSlotsToClear; + + /** + * Specifies if this layer command is on type modify, create or destroy. + * This command is replacing the older IComposerClient.createLayer and destroyLayer + * and making it more efficient with reduced aidls to the HAL. + * The HAL will report the errors by setting CommandResultPayload::CommandError. + */ + LayerLifecycleBatchCommandType layerLifecycleBatchCommandType; + + /** + * Specifies the number of buffer slot to be reserved. + */ + int newBufferSlotCount; } diff --git a/graphics/composer/aidl/android/hardware/graphics/composer3/LayerLifecycleBatchCommandType.aidl b/graphics/composer/aidl/android/hardware/graphics/composer3/LayerLifecycleBatchCommandType.aidl new file mode 100644 index 0000000000..ec2d55f791 --- /dev/null +++ b/graphics/composer/aidl/android/hardware/graphics/composer3/LayerLifecycleBatchCommandType.aidl @@ -0,0 +1,39 @@ +/** + * Copyright (c) 2023, 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; + +/** + * Possible batch command types for a given layer. + */ +@VintfStability +@Backing(type="int") +enum LayerLifecycleBatchCommandType { + /** + * Layer attributes are being modified for already created layer. + */ + MODIFY = 0, + /** + * This indicates that the current LayerCommand should also create the layer, + * before processing the other attributes in the LayerCommand. + */ + CREATE = 1, + /** + * This indicates that the current LayerCommand should also destroyes the layer, + * after processing the other attributes in the LayerCommand. + */ + DESTROY = 2, +} 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 c7bd5e0d11..a1ccbfe047 100644 --- a/graphics/composer/aidl/include/android/hardware/graphics/composer3/ComposerClientWriter.h +++ b/graphics/composer/aidl/include/android/hardware/graphics/composer3/ComposerClientWriter.h @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -99,6 +100,15 @@ class ComposerClientWriter final { getBufferCommand(slot, buffer, releaseFence)); } + void setLayerLifecycleBatchCommandType(int64_t display, int64_t layer, + LayerLifecycleBatchCommandType cmd) { + getLayerCommand(display, layer).layerLifecycleBatchCommandType = cmd; + } + + void setNewBufferSlotCount(int64_t display, int64_t layer, int32_t newBufferSlotToCount) { + getLayerCommand(display, layer).newBufferSlotCount = newBufferSlotToCount; + } + void validateDisplay(int64_t display, std::optional expectedPresentTime, int32_t frameIntervalNs) { diff --git a/graphics/composer/aidl/vts/VtsHalGraphicsComposer3_TargetTest.cpp b/graphics/composer/aidl/vts/VtsHalGraphicsComposer3_TargetTest.cpp index ca1b6d82de..a53eb384e7 100644 --- a/graphics/composer/aidl/vts/VtsHalGraphicsComposer3_TargetTest.cpp +++ b/graphics/composer/aidl/vts/VtsHalGraphicsComposer3_TargetTest.cpp @@ -2913,6 +2913,69 @@ TEST_P(GraphicsComposerAidlCommandTest, MultiThreadedPresent) { } } +class GraphicsComposerAidlBatchedCommandTest : public GraphicsComposerAidlCommandTest { + protected: + void SetUp() override { + GraphicsComposerAidlCommandTest::SetUp(); + if (getInterfaceVersion() <= 2) { + GTEST_SKIP() << "Device interface version is expected to be >= 3"; + } + } + void TearDown() override { + const auto errors = mReader.takeErrors(); + ASSERT_TRUE(mReader.takeErrors().empty()); + ASSERT_NO_FATAL_FAILURE(GraphicsComposerAidlTest::TearDown()); + } +}; + +TEST_P(GraphicsComposerAidlBatchedCommandTest, CreateBatchedCommand) { + auto& writer = getWriter(getPrimaryDisplayId()); + int64_t layer = 5; + writer.setLayerLifecycleBatchCommandType(getPrimaryDisplayId(), layer, + LayerLifecycleBatchCommandType::CREATE); + writer.setNewBufferSlotCount(getPrimaryDisplayId(), layer, 1); + writer.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp, + VtsComposerClient::kNoFrameIntervalNs); + execute(); + ASSERT_TRUE(mReader.takeErrors().empty()); +} + +TEST_P(GraphicsComposerAidlBatchedCommandTest, DestroyBatchedCommand) { + auto& writer = getWriter(getPrimaryDisplayId()); + int64_t layer = 5; + writer.setLayerLifecycleBatchCommandType(getPrimaryDisplayId(), layer, + LayerLifecycleBatchCommandType::CREATE); + writer.setNewBufferSlotCount(getPrimaryDisplayId(), layer, 1); + writer.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp, + VtsComposerClient::kNoFrameIntervalNs); + execute(); + ASSERT_TRUE(mReader.takeErrors().empty()); + writer.setLayerLifecycleBatchCommandType(getPrimaryDisplayId(), layer, + LayerLifecycleBatchCommandType::DESTROY); + layer++; + writer.setLayerLifecycleBatchCommandType(getPrimaryDisplayId(), layer, + LayerLifecycleBatchCommandType::CREATE); + writer.setNewBufferSlotCount(getPrimaryDisplayId(), layer, 1); + + execute(); + ASSERT_TRUE(mReader.takeErrors().empty()); +} + +TEST_P(GraphicsComposerAidlBatchedCommandTest, NoCreateDestroyBatchedCommandIncorrectLayer) { + auto& writer = getWriter(getPrimaryDisplayId()); + int64_t layer = 5; + writer.setLayerLifecycleBatchCommandType(getPrimaryDisplayId(), layer, + LayerLifecycleBatchCommandType::DESTROY); + execute(); + const auto errors = mReader.takeErrors(); + ASSERT_TRUE(errors.size() == 1 && errors[0].errorCode == IComposerClient::EX_BAD_LAYER); +} + +GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsComposerAidlBatchedCommandTest); +INSTANTIATE_TEST_SUITE_P( + PerInstance, GraphicsComposerAidlBatchedCommandTest, + testing::ValuesIn(::android::getAidlHalInstanceNames(IComposer::descriptor)), + ::android::PrintInstanceNameToString); GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsComposerAidlCommandTest); INSTANTIATE_TEST_SUITE_P( PerInstance, GraphicsComposerAidlCommandTest,