From bee19021e3f9136d3762d764144c738da13f4bde Mon Sep 17 00:00:00 2001 From: ramindani Date: Tue, 29 Oct 2024 09:20:22 -0700 Subject: Adds getSupportedRefreshRates support Source values for refresh rates from the RefreshRateSelector through SurfaceComposerClient. Test: atest android.display.cts.DisplayTest BUG: 365163968 Flag: com.android.server.display.feature.flags.enable_get_supported_refresh_rates Change-Id: I149e6e51b3b3718ef53e522f1fca5650dbbd8b7b --- libs/gui/SurfaceComposerClient.cpp | 5 +++++ libs/gui/aidl/android/gui/DynamicDisplayInfo.aidl | 3 +++ libs/ui/include/ui/DynamicDisplayInfo.h | 3 +++ services/surfaceflinger/Scheduler/RefreshRateSelector.cpp | 13 +++++++++++++ services/surfaceflinger/Scheduler/RefreshRateSelector.h | 2 ++ services/surfaceflinger/SurfaceFlinger.cpp | 7 +++++++ 6 files changed, 33 insertions(+) diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp index 61aabaa7f6..2603977466 100644 --- a/libs/gui/SurfaceComposerClient.cpp +++ b/libs/gui/SurfaceComposerClient.cpp @@ -2873,6 +2873,11 @@ void SurfaceComposerClient::getDynamicDisplayInfoInternal(gui::DynamicDisplayInf outInfo->hasArrSupport = ginfo.hasArrSupport; outInfo->frameRateCategoryRate = ui::FrameRateCategoryRate(ginfo.frameRateCategoryRate.normal, ginfo.frameRateCategoryRate.high); + outInfo->supportedRefreshRates.clear(); + outInfo->supportedRefreshRates.reserve(ginfo.supportedRefreshRates.size()); + for (const auto rate : ginfo.supportedRefreshRates) { + outInfo->supportedRefreshRates.push_back(static_cast(rate)); + } } status_t SurfaceComposerClient::getDynamicDisplayInfoFromId(int64_t displayId, diff --git a/libs/gui/aidl/android/gui/DynamicDisplayInfo.aidl b/libs/gui/aidl/android/gui/DynamicDisplayInfo.aidl index 67cc273fce..26c12c56f3 100644 --- a/libs/gui/aidl/android/gui/DynamicDisplayInfo.aidl +++ b/libs/gui/aidl/android/gui/DynamicDisplayInfo.aidl @@ -50,4 +50,7 @@ parcelable DynamicDisplayInfo { // Represents frame rate for FrameRateCategory Normal and High. FrameRateCategoryRate frameRateCategoryRate; + + // All the refresh rates supported for the default display mode. + float[] supportedRefreshRates; } diff --git a/libs/ui/include/ui/DynamicDisplayInfo.h b/libs/ui/include/ui/DynamicDisplayInfo.h index af494dcf39..9d97151155 100644 --- a/libs/ui/include/ui/DynamicDisplayInfo.h +++ b/libs/ui/include/ui/DynamicDisplayInfo.h @@ -59,6 +59,9 @@ struct DynamicDisplayInfo { // Represents frame rate for FrameRateCategory Normal and High. ui::FrameRateCategoryRate frameRateCategoryRate; + + // All the refresh rates supported for the default display mode. + std::vector supportedRefreshRates; }; } // namespace android::ui diff --git a/services/surfaceflinger/Scheduler/RefreshRateSelector.cpp b/services/surfaceflinger/Scheduler/RefreshRateSelector.cpp index 84fa1390a4..7f763e565d 100644 --- a/services/surfaceflinger/Scheduler/RefreshRateSelector.cpp +++ b/services/surfaceflinger/Scheduler/RefreshRateSelector.cpp @@ -1569,6 +1569,19 @@ Fps RefreshRateSelector::findClosestKnownFrameRate(Fps frameRate) const { return distance1 < distance2 ? *lowerBound : *std::prev(lowerBound); } +std::vector RefreshRateSelector::getSupportedFrameRates() const { + std::scoped_lock lock(mLock); + // TODO(b/356986687) Remove the limit once we have the anchor list implementation. + const size_t frameRatesSize = std::min(11, mPrimaryFrameRates.size()); + std::vector supportedFrameRates; + supportedFrameRates.reserve(frameRatesSize); + std::transform(mPrimaryFrameRates.rbegin(), + mPrimaryFrameRates.rbegin() + static_cast(frameRatesSize), + std::back_inserter(supportedFrameRates), + [](FrameRateMode mode) { return mode.fps.getValue(); }); + return supportedFrameRates; +} + auto RefreshRateSelector::getIdleTimerAction() const -> KernelIdleTimerAction { std::lock_guard lock(mLock); diff --git a/services/surfaceflinger/Scheduler/RefreshRateSelector.h b/services/surfaceflinger/Scheduler/RefreshRateSelector.h index ee3a4f7bdc..508f9d72ea 100644 --- a/services/surfaceflinger/Scheduler/RefreshRateSelector.h +++ b/services/surfaceflinger/Scheduler/RefreshRateSelector.h @@ -441,6 +441,8 @@ public: std::pair getFrameRateCategoryRates() const { return kFrameRateCategoryRates; } + std::vector getSupportedFrameRates() const EXCLUDES(mLock); + private: friend struct TestableRefreshRateSelector; diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 9854174bbd..de94c264a8 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -1229,6 +1229,8 @@ void SurfaceFlinger::getDynamicDisplayInfoInternal(ui::DynamicDisplayInfo*& info const auto [normal, high] = display->refreshRateSelector().getFrameRateCategoryRates(); ui::FrameRateCategoryRate frameRateCategoryRate(normal.getValue(), high.getValue()); info->frameRateCategoryRate = frameRateCategoryRate; + + info->supportedRefreshRates = display->refreshRateSelector().getSupportedFrameRates(); info->activeColorMode = display->getCompositionDisplay()->getState().colorMode; info->hdrCapabilities = filterOut4k30(display->getHdrCapabilities()); @@ -8581,6 +8583,11 @@ void SurfaceComposerAIDL::getDynamicDisplayInfoInternal(ui::DynamicDisplayInfo& gui::FrameRateCategoryRate& frameRateCategoryRate = outInfo->frameRateCategoryRate; frameRateCategoryRate.normal = info.frameRateCategoryRate.getNormal(); frameRateCategoryRate.high = info.frameRateCategoryRate.getHigh(); + outInfo->supportedRefreshRates.clear(); + outInfo->supportedRefreshRates.reserve(info.supportedRefreshRates.size()); + for (float supportedRefreshRate : info.supportedRefreshRates) { + outInfo->supportedRefreshRates.push_back(supportedRefreshRate); + } outInfo->supportedColorModes.clear(); outInfo->supportedColorModes.reserve(info.supportedColorModes.size()); -- cgit v1.2.3-59-g8ed1b