drm_hwcomposer: Stop using HWC2 hooks for CompositionType
Add a member to LayerProperties for composition_type, and set
composition type along with other layer properties.
If the client requests an unsupported CompositionType, it's expected
that the HWC will detect this and return an error, and not proceed with
further validation of LayerCommand parameters.
Change-Id: Icf6d4becb53267f470226ed63b311ac7704d9e12
Signed-off-by: Drew Davenport <ddavenport@google.com>
diff --git a/hwc2_device/HwcLayer.cpp b/hwc2_device/HwcLayer.cpp
index ec41627..9f2888e 100644
--- a/hwc2_device/HwcLayer.cpp
+++ b/hwc2_device/HwcLayer.cpp
@@ -34,6 +34,9 @@
if (layer_properties.sample_range) {
sample_range_ = layer_properties.sample_range.value();
}
+ if (layer_properties.composition_type) {
+ sf_type_ = layer_properties.composition_type.value();
+ }
}
// NOLINTNEXTLINE(readability-convert-member-functions-to-static)
diff --git a/hwc2_device/HwcLayer.h b/hwc2_device/HwcLayer.h
index eb02798..ad53097 100644
--- a/hwc2_device/HwcLayer.h
+++ b/hwc2_device/HwcLayer.h
@@ -33,6 +33,7 @@
std::optional<BufferBlendMode> blend_mode;
std::optional<BufferColorSpace> color_space;
std::optional<BufferSampleRange> sample_range;
+ std::optional<HWC2::Composition> composition_type;
};
explicit HwcLayer(HwcDisplay *parent_display) : parent_(parent_display){};
diff --git a/hwc3/ComposerClient.cpp b/hwc3/ComposerClient.cpp
index b33f387..c344b1c 100644
--- a/hwc3/ComposerClient.cpp
+++ b/hwc3/ComposerClient.cpp
@@ -131,6 +131,56 @@
}
}
+bool IsSupportedCompositionType(
+ const std::optional<ParcelableComposition> composition) {
+ if (!composition) {
+ return true;
+ }
+ switch (composition->composition) {
+ case Composition::INVALID:
+ case Composition::CLIENT:
+ case Composition::DEVICE:
+ case Composition::SOLID_COLOR:
+ case Composition::CURSOR:
+ return true;
+
+ // Unsupported composition types. Set an error for the current
+ // DisplayCommand and return.
+ case Composition::DISPLAY_DECORATION:
+ case Composition::SIDEBAND:
+ case Composition::REFRESH_RATE_INDICATOR:
+ return false;
+ }
+}
+
+std::optional<HWC2::Composition> AidlToCompositionType(
+ const std::optional<ParcelableComposition> composition) {
+ if (!composition) {
+ return std::nullopt;
+ }
+
+ switch (composition->composition) {
+ case Composition::INVALID:
+ return HWC2::Composition::Invalid;
+ case Composition::CLIENT:
+ return HWC2::Composition::Client;
+ case Composition::DEVICE:
+ return HWC2::Composition::Device;
+ case Composition::SOLID_COLOR:
+ return HWC2::Composition::SolidColor;
+ case Composition::CURSOR:
+ return HWC2::Composition::Cursor;
+
+ // Unsupported composition types.
+ case Composition::DISPLAY_DECORATION:
+ case Composition::SIDEBAND:
+ case Composition::REFRESH_RATE_INDICATOR:
+ ALOGE("Unsupported composition type: %s",
+ toString(composition->composition).c_str());
+ return std::nullopt;
+ }
+}
+
DisplayConfiguration HwcDisplayConfigToAidlConfiguration(
const HwcDisplayConfigs& configs, const HwcDisplayConfig& config) {
DisplayConfiguration aidl_configuration =
@@ -396,19 +446,25 @@
return;
}
+ // If the requested composition type is not supported, the HWC should return
+ // an error and not process any further commands.
+ if (!IsSupportedCompositionType(command.composition)) {
+ cmd_result_writer_->AddError(hwc3::Error::kUnsupported);
+ return;
+ }
+
HwcLayerWrapper layer_wrapper{command.layer, layer};
if (command.buffer) {
ExecuteSetLayerBuffer(display_id, layer_wrapper, *command.buffer);
}
+
HwcLayer::LayerProperties properties;
properties.blend_mode = AidlToBlendMode(command.blendMode);
properties.color_space = AidlToColorSpace(command.dataspace);
properties.sample_range = AidlToSampleRange(command.dataspace);
+ properties.composition_type = AidlToCompositionType(command.composition);
layer->SetLayerProperties(properties);
- if (command.composition) {
- ExecuteSetLayerComposition(display_id, layer_wrapper, *command.composition);
- }
if (command.displayFrame) {
ExecuteSetLayerDisplayFrame(display_id, layer_wrapper,
*command.displayFrame);
@@ -1119,26 +1175,6 @@
}
}
-void ComposerClient::ExecuteSetLayerComposition(
- int64_t /*display_id*/, HwcLayerWrapper& layer,
- const ParcelableComposition& composition) {
- hwc3::Error error = hwc3::Error::kNone;
- switch (composition.composition) {
- // Unsupported composition types should set an error for the current
- // DisplayCommand.
- case Composition::DISPLAY_DECORATION:
- case Composition::SIDEBAND:
- error = hwc3::Error::kUnsupported;
- break;
- default:
- error = Hwc2toHwc3Error(layer.layer->SetLayerCompositionType(
- Hwc3CompositionToHwc2(composition.composition)));
- }
- if (error != hwc3::Error::kNone) {
- cmd_result_writer_->AddError(error);
- }
-}
-
void ComposerClient::ExecuteSetLayerDisplayFrame(int64_t /*display_id*/,
HwcLayerWrapper& layer,
const common::Rect& rect) {
diff --git a/hwc3/ComposerClient.h b/hwc3/ComposerClient.h
index dfa9416..f295e52 100644
--- a/hwc3/ComposerClient.h
+++ b/hwc3/ComposerClient.h
@@ -160,8 +160,6 @@
void DispatchLayerCommand(int64_t display_id, const LayerCommand& command);
void ExecuteSetLayerBuffer(int64_t display_id, HwcLayerWrapper& layer_id,
const Buffer& buffer);
- void ExecuteSetLayerComposition(int64_t display_id, HwcLayerWrapper& layer,
- const ParcelableComposition& composition);
void ExecuteSetLayerDisplayFrame(int64_t display_id, HwcLayerWrapper& layer,
const common::Rect& rect);
void ExecuteSetLayerPlaneAlpha(int64_t display_id, HwcLayerWrapper& layer,
diff --git a/hwc3/Utils.h b/hwc3/Utils.h
index 51f49c6..3887440 100644
--- a/hwc3/Utils.h
+++ b/hwc3/Utils.h
@@ -94,13 +94,6 @@
return static_cast<Composition>(composition_type);
}
-inline int32_t Hwc3CompositionToHwc2(Composition composition_type) {
- if (composition_type > Composition::SIDEBAND) {
- return HWC2_COMPOSITION_INVALID;
- }
- return static_cast<int32_t>(composition_type);
-}
-
// Values for color modes match across HWC versions, so static cast is safe:
// https://android.googlesource.com/platform/hardware/interfaces/+/refs/heads/main/graphics/composer/aidl/android/hardware/graphics/composer3/ColorMode.aidl
// https://cs.android.com/android/platform/superproject/main/+/main:system/core/libsystem/include/system/graphics-base-v1.0.h;drc=7d940ae4afa450696afa25e07982f3a95e17e9b2;l=118