From a5fb437d37ccb620d6fd45739a37c2b8ba995331 Mon Sep 17 00:00:00 2001 From: Drew Davenport Date: Tue, 3 Jun 2025 00:57:23 +0000 Subject: [PATCH] drm_hwcomposer: Move CompositionType out of HwcLayer struct Moving this paves the way for reducing dependency on HwcLayer from the Backend class Change-Id: I62f057a0efcb7afc3c9a04cff3bd53b5c56c5ad9 --- backend/Backend.cpp | 24 ++++++++++++------------ backend/Backend.h | 2 +- backend/BackendClient.cpp | 2 +- compositor/LayerData.h | 2 ++ hwc/HwcDisplay.cpp | 26 +++++++++++++------------- hwc/HwcDisplay.h | 2 +- hwc/HwcLayer.h | 7 ------- hwc2_device/hwc2_device.cpp | 9 ++++----- hwc3/ComposerClient.cpp | 13 +++++++------ 9 files changed, 41 insertions(+), 46 deletions(-) diff --git a/backend/Backend.cpp b/backend/Backend.cpp index 1d177dc..3aecfae 100644 --- a/backend/Backend.cpp +++ b/backend/Backend.cpp @@ -31,7 +31,7 @@ HwcLayer *GetCursorLayer(const std::vector &layers) { auto it = std::find_if(layers.begin(), layers.end(), [&](auto *layer) -> bool { return layer->GetSfType() == - HwcLayer::CompositionType::kCursor; + CompositionType::kCursor; }); if (it == layers.end()) { return nullptr; @@ -148,9 +148,9 @@ bool Backend::IsClientLayer(HwcDisplay *display, HwcLayer *layer) { display->GetHwc()->GetResMan().ForcedScalingWithGpu()); } -bool Backend::HardwareSupportsLayerType(HwcLayer::CompositionType comp_type) { - return comp_type == HwcLayer::CompositionType::kDevice || - comp_type == HwcLayer::CompositionType::kCursor; +bool Backend::HardwareSupportsLayerType(CompositionType comp_type) { + return comp_type == CompositionType::kDevice || + comp_type == CompositionType::kCursor; } uint32_t Backend::CalcPixOps(const std::vector &layers, @@ -179,12 +179,12 @@ void Backend::MarkValidated(std::vector &layers, bool use_cursor_plane) { for (size_t z_order = 0; z_order < layers.size(); ++z_order) { if (z_order >= client_first_z && z_order < client_first_z + client_size) { - layers[z_order]->SetValidatedType(HwcLayer::CompositionType::kClient); - } else if (use_cursor_plane && layers[z_order]->GetSfType() == - HwcLayer::CompositionType::kCursor) { - layers[z_order]->SetValidatedType(HwcLayer::CompositionType::kCursor); + layers[z_order]->SetValidatedType(CompositionType::kClient); + } else if (use_cursor_plane && + layers[z_order]->GetSfType() == CompositionType::kCursor) { + layers[z_order]->SetValidatedType(CompositionType::kCursor); } else { - layers[z_order]->SetValidatedType(HwcLayer::CompositionType::kDevice); + layers[z_order]->SetValidatedType(CompositionType::kDevice); } } } @@ -198,8 +198,8 @@ std::tuple Backend::GetExtraClientRange( // Cursor plane is not counted among |avail_planes|, so the cursor layer // shouldn't be counted in |layers_size|. if (use_cursor_plane) { - ALOGE_IF(layers.empty() || layers.back()->GetSfType() != - HwcLayer::CompositionType::kCursor, + ALOGE_IF(layers.empty() || + layers.back()->GetSfType() != CompositionType::kCursor, "Cursor layer was not found at highest z-order"); --layers_size; } @@ -213,7 +213,7 @@ std::tuple Backend::GetExtraClientRange( // If the cursor plane isn't being used, reserve a plane for the cursor to be // device composited. if (!use_cursor_plane && avail_planes > 0 && layers_size > 0 && - layers.back()->GetSfType() == HwcLayer::CompositionType::kCursor) { + layers.back()->GetSfType() == CompositionType::kCursor) { avail_planes--; layers_size--; } diff --git a/backend/Backend.h b/backend/Backend.h index 09d4853..5c8e375 100644 --- a/backend/Backend.h +++ b/backend/Backend.h @@ -32,7 +32,7 @@ class Backend { virtual bool IsClientLayer(HwcDisplay *display, HwcLayer *layer); protected: - static bool HardwareSupportsLayerType(HwcLayer::CompositionType comp_type); + static bool HardwareSupportsLayerType(CompositionType comp_type); static uint32_t CalcPixOps(const std::vector &layers, size_t first_z, size_t size, std::pair display_size); diff --git a/backend/BackendClient.cpp b/backend/BackendClient.cpp index d262ba3..dfe38f8 100644 --- a/backend/BackendClient.cpp +++ b/backend/BackendClient.cpp @@ -22,7 +22,7 @@ namespace android { void BackendClient::ValidateDisplay(HwcDisplay *display) { for (auto &[layer_handle, layer] : display->layers()) { - layer.SetValidatedType(HwcLayer::CompositionType::kClient); + layer.SetValidatedType(CompositionType::kClient); } } diff --git a/compositor/LayerData.h b/compositor/LayerData.h index 93793ff..21e7269 100644 --- a/compositor/LayerData.h +++ b/compositor/LayerData.h @@ -32,6 +32,8 @@ class DrmFbIdHandle; using ILayerId = int64_t; +enum class CompositionType { kInvalid, kClient, kDevice, kSolidColor, kCursor }; + /* Rotation is defined in the clockwise direction */ /* The flip is done before rotation */ struct LayerTransform { diff --git a/hwc/HwcDisplay.cpp b/hwc/HwcDisplay.cpp index e7a7a36..3c7353c 100644 --- a/hwc/HwcDisplay.cpp +++ b/hwc/HwcDisplay.cpp @@ -304,11 +304,11 @@ auto HwcDisplay::ValidateStagedComposition() -> std::vector { */ for (auto &l : layers_) { l.second.SetPriorBufferScanOutFlag(l.second.GetValidatedType() != - HwcLayer::CompositionType::kClient); + CompositionType::kClient); /* Populate layer data for layers that might be mapped to a drm plane. */ - if (l.second.GetSfType() == HwcLayer::CompositionType::kDevice || - l.second.GetSfType() == HwcLayer::CompositionType::kCursor) { + if (l.second.GetSfType() == CompositionType::kDevice || + l.second.GetSfType() == CompositionType::kCursor) { l.second.PopulateLayerData(); } } @@ -798,10 +798,10 @@ bool HwcDisplay::CreateComposition(AtomicCommitArgs &a_args) { std::optional cursor_layer = std::nullopt; for (auto &[_, layer] : layers_) { switch (layer.GetValidatedType()) { - case HwcLayer::CompositionType::kDevice: + case CompositionType::kDevice: z_map.emplace(layer.GetZOrder(), &layer); break; - case HwcLayer::CompositionType::kCursor: + case CompositionType::kCursor: if (!cursor_layer.has_value()) { cursor_layer = layer.GetLayerData(); } else { @@ -809,14 +809,14 @@ bool HwcDisplay::CreateComposition(AtomicCommitArgs &a_args) { z_map.emplace(layer.GetZOrder(), &layer); } break; - case HwcLayer::CompositionType::kClient: + case CompositionType::kClient: // Place it at the z_order of the lowest client layer use_client_layer = true; client_layer_count++; client_z_order = std::min(client_z_order, layer.GetZOrder()); break; - case HwcLayer::CompositionType::kSolidColor: - case HwcLayer::CompositionType::kInvalid: + case CompositionType::kSolidColor: + case CompositionType::kInvalid: ALOGE("Invalid layer type: %d", static_cast(layer.GetValidatedType())); continue; @@ -979,9 +979,9 @@ std::vector HwcDisplay::GetOrderLayersByZPos() { std::sort(std::begin(ordered_layers), std::end(ordered_layers), [](const HwcLayer *lhs, const HwcLayer *rhs) { // Cursor layers should always have highest zpos. - if ((lhs->GetSfType() == HwcLayer::CompositionType::kCursor) != - (rhs->GetSfType() == HwcLayer::CompositionType::kCursor)) { - return rhs->GetSfType() == HwcLayer::CompositionType::kCursor; + if ((lhs->GetSfType() == CompositionType::kCursor) != + (rhs->GetSfType() == CompositionType::kCursor)) { + return rhs->GetSfType() == CompositionType::kCursor; } return lhs->GetZOrder() < rhs->GetZOrder(); @@ -1055,8 +1055,8 @@ void HwcDisplay::set_backend(std::unique_ptr backend) { bool HwcDisplay::NeedsClientLayerUpdate() const { return std::any_of(layers_.begin(), layers_.end(), [](const auto &pair) { const auto &layer = pair.second; - return layer.GetSfType() == HwcLayer::CompositionType::kClient || - layer.GetValidatedType() == HwcLayer::CompositionType::kClient; + return layer.GetSfType() == CompositionType::kClient || + layer.GetValidatedType() == CompositionType::kClient; }); } diff --git a/hwc/HwcDisplay.h b/hwc/HwcDisplay.h index 92a256d..4951408 100644 --- a/hwc/HwcDisplay.h +++ b/hwc/HwcDisplay.h @@ -106,7 +106,7 @@ class HwcDisplay { // To be called after SetDisplayProperties. Returns an empty vector if the // requested layers have been validated, otherwise the vector describes // the requested composition type changes. - using ChangedLayer = std::pair; + using ChangedLayer = std::pair; auto ValidateStagedComposition() -> std::vector; // Mark previously validated properties as ready to present. diff --git a/hwc/HwcLayer.h b/hwc/HwcLayer.h index eb83f0b..31c3a5d 100644 --- a/hwc/HwcLayer.h +++ b/hwc/HwcLayer.h @@ -42,13 +42,6 @@ class HwcLayer { int32_t slot_id; SharedFd fence; }; - enum class CompositionType { - kInvalid, - kClient, - kDevice, - kSolidColor, - kCursor - }; // A set of properties to be validated. struct LayerProperties { std::optional slot_buffer; diff --git a/hwc2_device/hwc2_device.cpp b/hwc2_device/hwc2_device.cpp index 09497f7..dce30e2 100644 --- a/hwc2_device/hwc2_device.cpp +++ b/hwc2_device/hwc2_device.cpp @@ -1190,17 +1190,16 @@ static int32_t SetLayerCompositionType(hwc2_device_t *device, HwcLayer::LayerProperties layer_properties; switch (static_cast(type)) { case HWC2::Composition::Client: - layer_properties.composition_type = HwcLayer::CompositionType::kClient; + layer_properties.composition_type = CompositionType::kClient; break; case HWC2::Composition::Device: - layer_properties.composition_type = HwcLayer::CompositionType::kDevice; + layer_properties.composition_type = CompositionType::kDevice; break; case HWC2::Composition::SolidColor: - layer_properties - .composition_type = HwcLayer::CompositionType::kSolidColor; + layer_properties.composition_type = CompositionType::kSolidColor; break; case HWC2::Composition::Cursor: - layer_properties.composition_type = HwcLayer::CompositionType::kCursor; + layer_properties.composition_type = CompositionType::kCursor; break; default: ALOGE("Unsupported composition type t=%d", type); diff --git a/hwc3/ComposerClient.cpp b/hwc3/ComposerClient.cpp index cd64309..c1b049c 100644 --- a/hwc3/ComposerClient.cpp +++ b/hwc3/ComposerClient.cpp @@ -52,6 +52,7 @@ using ::android::CompositionStatsAtomReporter; using ::android::CompositionStatsPoller; +using ::android::CompositionType; using ::android::DamageInfo; using ::android::DisplayHandle; using ::android::DstRectInfo; @@ -216,7 +217,7 @@ std::optional> AidlToColorTransformMatrix( return color_transform_matrix; } -std::optional AidlToCompositionType( +std::optional AidlToCompositionType( const std::optional composition) { if (!composition) { return std::nullopt; @@ -224,15 +225,15 @@ std::optional AidlToCompositionType( switch (composition->composition) { case Composition::INVALID: - return HwcLayer::CompositionType::kInvalid; + return CompositionType::kInvalid; case Composition::CLIENT: - return HwcLayer::CompositionType::kClient; + return CompositionType::kClient; case Composition::DEVICE: - return HwcLayer::CompositionType::kDevice; + return CompositionType::kDevice; case Composition::SOLID_COLOR: - return HwcLayer::CompositionType::kSolidColor; + return CompositionType::kSolidColor; case Composition::CURSOR: - return HwcLayer::CompositionType::kCursor; + return CompositionType::kCursor; // Unsupported composition types. case Composition::DISPLAY_DECORATION: