From 3ceb722bc9251cd479b2571d75db55e04984ca5d Mon Sep 17 00:00:00 2001 From: Andrew Wolfers Date: Wed, 10 Sep 2025 13:39:23 +0000 Subject: [PATCH] drm_hwcomposer: Move pixops calculation This change moves the pixops calculation into HwcLayer. This simplifies the logic to determine the total pixops over the client range performed within Backend. This change also moves the display size calculation into HwcDisplay. Change-Id: Id7e12657a512db3aaea98d88833c818c10efef66 --- backend/Backend.cpp | 32 +++++--------------------------- backend/Backend.h | 3 +-- hwc/HwcDisplay.cpp | 11 ++++++++++- hwc/HwcDisplay.h | 2 ++ hwc/HwcLayer.cpp | 8 ++++++++ hwc/HwcLayer.h | 4 ++++ 6 files changed, 30 insertions(+), 30 deletions(-) diff --git a/backend/Backend.cpp b/backend/Backend.cpp index 64549e3..12e277e 100644 --- a/backend/Backend.cpp +++ b/backend/Backend.cpp @@ -40,16 +40,6 @@ const HwcLayer* GetCursorLayer(const std::vector& layers) { return *it; } -std::pair GetDisplaySize(const HwcDisplay *display) { - const auto *config = display->GetNextConfig(); - if (config == nullptr) { - return std::make_pair(0, 0); - } - - return std::make_pair(config->mode.GetRawMode().hdisplay, - config->mode.GetRawMode().vdisplay); -} - } // namespace auto Backend::ValidateDisplay(HwcDisplay* display) -> ValidatedComposition { @@ -113,10 +103,8 @@ auto Backend::ValidateDisplay(HwcDisplay* display) -> ValidatedComposition { } display->total_stats().gpu_pixops += CalcPixOps(layers, client_start, - client_size, - GetDisplaySize(display)); - display->total_stats().total_pixops += CalcPixOps(layers, 0, layers.size(), - GetDisplaySize(display)); + client_size); + display->total_stats().total_pixops += CalcPixOps(layers, 0, layers.size()); if (use_cursor_plane) { ++display->total_stats().cursor_plane_frames; } @@ -162,22 +150,13 @@ bool Backend::HardwareSupportsLayerType(CompositionType comp_type) { } uint32_t Backend::CalcPixOps(const std::vector& layers, - size_t first_z, size_t size, - std::pair display_size) { - uint32_t whole_display = display_size.first * display_size.second; + size_t first_z, size_t size) { uint32_t pixops = 0; ALOGE_IF(first_z + size > layers.size(), "CalcPixOps provided range outside of layers"); for (size_t z_order = first_z; z_order < std::min(first_z + size, layers.size()); ++z_order) { - const auto* layer = layers[z_order]; - const auto& df = layer->GetLayerData().pi.display_frame; - if (df.i_rect.has_value()) { - pixops += df.i_rect->Width() * df.i_rect->Height(); - } else { - // nullopt frame rect means whole display. - pixops += whole_display; - } + pixops += layers[z_order]->GetPixOps(); } return pixops; } @@ -255,8 +234,7 @@ std::tuple Backend::GetExtraClientRange( // fewest GPU pixops. uint32_t gpu_pixops = UINT32_MAX; for (size_t i = 0; i < steps; i++) { - const uint32_t po = CalcPixOps(layers, start + i, client_size, - GetDisplaySize(display)); + const uint32_t po = CalcPixOps(layers, start + i, client_size); if (po < gpu_pixops) { gpu_pixops = po; client_start = start + i; diff --git a/backend/Backend.h b/backend/Backend.h index 2c2f347..30eaca9 100644 --- a/backend/Backend.h +++ b/backend/Backend.h @@ -54,8 +54,7 @@ class Backend { const std::vector& layers); 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); + size_t first_z, size_t size); static CompositionTypeMap GetCompositionTypes( const std::vector& layers, size_t client_first_z, size_t client_size, bool use_cursor_plane); diff --git a/hwc/HwcDisplay.cpp b/hwc/HwcDisplay.cpp index c4ffc7f..980f91b 100644 --- a/hwc/HwcDisplay.cpp +++ b/hwc/HwcDisplay.cpp @@ -1069,7 +1069,7 @@ void HwcDisplay::SetHdrOutputMetadata(ui::Hdr type) { m->eotf = 3; // HLG break; default: - ALOGW("HDR type %d is not supported.", type); + ALOGW("HDR type %d is not supported.", static_cast(type)); return; } @@ -1176,4 +1176,13 @@ void HwcDisplay::SetConfigGroupsForActiveConfig() { configs_.SanitizeGroups(); } +std::pair HwcDisplay::GetSize() const { + const auto *config = GetNextConfig(); + if (config == nullptr) { + return std::make_pair(0, 0); + } + return std::make_pair(config->mode.GetRawMode().hdisplay, + config->mode.GetRawMode().vdisplay); +} + } // namespace android::drm_hwcomposer diff --git a/hwc/HwcDisplay.h b/hwc/HwcDisplay.h index 704411e..db1e8e0 100644 --- a/hwc/HwcDisplay.h +++ b/hwc/HwcDisplay.h @@ -232,6 +232,8 @@ class HwcDisplay { bool NeedsClientLayerUpdate() const; + std::pair GetSize() const; + private: // Create AtomicCommitArgs to commit at the next vsync. Returns nullopt if // such AtomicCommitArgs cannot be created due to lack of drm resources or diff --git a/hwc/HwcLayer.cpp b/hwc/HwcLayer.cpp index f3482c2..f10ae06 100644 --- a/hwc/HwcLayer.cpp +++ b/hwc/HwcLayer.cpp @@ -132,4 +132,12 @@ bool HwcLayer::IsLayerUsableAsDevice() const { return it->second.fb != nullptr; } +uint32_t HwcLayer::GetPixOps() const { + const auto& df = GetLayerData().pi.display_frame; + if (df.i_rect.has_value()) { + return df.i_rect->Width() * df.i_rect->Height(); + } + return parent_->GetSize().first * parent_->GetSize().second; +} + } // namespace android::drm_hwcomposer diff --git a/hwc/HwcLayer.h b/hwc/HwcLayer.h index c28fafb..3ac6134 100644 --- a/hwc/HwcLayer.h +++ b/hwc/HwcLayer.h @@ -106,6 +106,10 @@ class HwcLayer { frontend_private_data_ = std::move(data); } + // Returns the number of pixel operations this layer would require if it were + // client-composited. + uint32_t GetPixOps() const; + private: // sf_type_ stores the initial type given to us by surfaceflinger, // validated_type_ stores the type after running ValidateDisplay