From 7ce70fea34e29df5849a3d6ca7167ae48eefc961 Mon Sep 17 00:00:00 2001 From: ramindani Date: Thu, 10 Feb 2022 18:08:09 +0000 Subject: [PATCH] Use Vector instead of unordered_map for hotplug displays For multi-display order of the hotplug matters, and vector maintains the order that we need for the multi-display. see: ag/1921760 for partner cl on HIDL. BUG: 210920960 BUG: 209409863 Test: atest VtsHalGraphicsComposer3_TargetTest Change-Id: I4f9a86413f20c860fc0bc3850a14335d62de881a --- .../composer-vts/GraphicsComposerCallback.cpp | 33 ++++++++++++++----- .../include/GraphicsComposerCallback.h | 4 +-- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/composer-vts/GraphicsComposerCallback.cpp b/graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/composer-vts/GraphicsComposerCallback.cpp index 22b5d796fc..8f329b3b4c 100644 --- a/graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/composer-vts/GraphicsComposerCallback.cpp +++ b/graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/composer-vts/GraphicsComposerCallback.cpp @@ -31,7 +31,7 @@ void GraphicsComposerCallback::setVsyncAllowed(bool allowed) { std::vector GraphicsComposerCallback::getDisplays() const { std::scoped_lock lock(mMutex); - return std::vector(mDisplays.begin(), mDisplays.end()); + return mDisplays; } int32_t GraphicsComposerCallback::getInvalidHotplugCount() const { @@ -81,22 +81,29 @@ GraphicsComposerCallback::takeLastVsyncPeriodChangeTimeline() { ::ndk::ScopedAStatus GraphicsComposerCallback::onHotplug(int64_t in_display, bool in_connected) { std::scoped_lock lock(mMutex); + + const auto it = std::find(mDisplays.begin(), mDisplays.end(), in_display); if (in_connected) { - if (!mDisplays.insert(in_display).second) { + if (it == mDisplays.end()) { + mDisplays.push_back(in_display); + } else { mInvalidHotplugCount++; } } else { - if (!mDisplays.erase(in_display)) { + if (it != mDisplays.end()) { + mDisplays.erase(it); + } else { mInvalidHotplugCount++; } } return ::ndk::ScopedAStatus::ok(); } -::ndk::ScopedAStatus GraphicsComposerCallback::onRefresh(int64_t display) { +::ndk::ScopedAStatus GraphicsComposerCallback::onRefresh(int64_t in_display) { std::scoped_lock lock(mMutex); - if (mDisplays.count(display) == 0) { + const auto it = std::find(mDisplays.begin(), mDisplays.end(), in_display); + if (it == mDisplays.end()) { mInvalidRefreshCount++; } @@ -106,7 +113,9 @@ GraphicsComposerCallback::takeLastVsyncPeriodChangeTimeline() { ::ndk::ScopedAStatus GraphicsComposerCallback::onVsync(int64_t in_display, int64_t in_timestamp, int32_t in_vsyncPeriodNanos) { std::scoped_lock lock(mMutex); - if (!mVsyncAllowed || mDisplays.count(in_display) == 0) { + + const auto it = std::find(mDisplays.begin(), mDisplays.end(), in_display); + if (!mVsyncAllowed || it == mDisplays.end()) { mInvalidVsyncCount++; } @@ -120,7 +129,9 @@ GraphicsComposerCallback::takeLastVsyncPeriodChangeTimeline() { const ::aidl::android::hardware::graphics::composer3::VsyncPeriodChangeTimeline& in_updatedTimeline) { std::scoped_lock lock(mMutex); - if (mDisplays.count(in_display) == 0) { + + const auto it = std::find(mDisplays.begin(), mDisplays.end(), in_display); + if (it == mDisplays.end()) { mInvalidVsyncPeriodChangeCount++; } mTimeline = in_updatedTimeline; @@ -130,7 +141,9 @@ GraphicsComposerCallback::takeLastVsyncPeriodChangeTimeline() { ::ndk::ScopedAStatus GraphicsComposerCallback::onSeamlessPossible(int64_t in_display) { std::scoped_lock lock(mMutex); - if (mDisplays.count(in_display)) { + + const auto it = std::find(mDisplays.begin(), mDisplays.end(), in_display); + if (it != mDisplays.end()) { mInvalidSeamlessPossibleCount++; } return ::ndk::ScopedAStatus::ok(); @@ -138,7 +151,9 @@ GraphicsComposerCallback::takeLastVsyncPeriodChangeTimeline() { ::ndk::ScopedAStatus GraphicsComposerCallback::onVsyncIdle(int64_t in_display) { std::scoped_lock lock(mMutex); - if (mDisplays.count(in_display)) { + + const auto it = std::find(mDisplays.begin(), mDisplays.end(), in_display); + if (it != mDisplays.end()) { mVsyncIdleCount++; mVsyncIdleTime = systemTime(); } diff --git a/graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/composer-vts/include/GraphicsComposerCallback.h b/graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/composer-vts/include/GraphicsComposerCallback.h index ced1020dc7..e54da346f5 100644 --- a/graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/composer-vts/include/GraphicsComposerCallback.h +++ b/graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/composer-vts/include/GraphicsComposerCallback.h @@ -18,7 +18,7 @@ #include #include #include -#include +#include namespace aidl::android::hardware::graphics::composer3::vts { @@ -58,7 +58,7 @@ class GraphicsComposerCallback : public BnComposerCallback { mutable std::mutex mMutex; // the set of all currently connected displays - std::unordered_set mDisplays GUARDED_BY(mMutex); + std::vector mDisplays GUARDED_BY(mMutex); // true only when vsync is enabled bool mVsyncAllowed GUARDED_BY(mMutex) = true;