diff options
| author | 2018-11-30 01:49:43 +0000 | |
|---|---|---|
| committer | 2018-11-30 01:49:43 +0000 | |
| commit | bd63715a39f577107a23d9068d6b71a3ea0e1c62 (patch) | |
| tree | 42c9410838f44e9d098147f236f2d2a5c455f360 /services/inputflinger/InputReaderBase.cpp | |
| parent | 1d9bcec52aec326fda0cb545feeb44f982ed8637 (diff) | |
| parent | 8158e7e33a95732b9963909b9fb471678ff8b7d4 (diff) | |
Merge "Add physical port to display viewport"
Diffstat (limited to 'services/inputflinger/InputReaderBase.cpp')
| -rw-r--r-- | services/inputflinger/InputReaderBase.cpp | 51 |
1 files changed, 44 insertions, 7 deletions
diff --git a/services/inputflinger/InputReaderBase.cpp b/services/inputflinger/InputReaderBase.cpp index 17a116e822..f48a64551e 100644 --- a/services/inputflinger/InputReaderBase.cpp +++ b/services/inputflinger/InputReaderBase.cpp @@ -49,14 +49,51 @@ bool InputReaderThread::threadLoop() { // --- InputReaderConfiguration --- -std::optional<DisplayViewport> InputReaderConfiguration::getDisplayViewport( - ViewportType viewportType, const std::string& uniqueDisplayId) const { +std::optional<DisplayViewport> InputReaderConfiguration::getDisplayViewportByUniqueId( + const std::string& uniqueDisplayId) const { + if (uniqueDisplayId.empty()) { + ALOGE("Empty string provided to %s", __func__); + return std::nullopt; + } + size_t count = 0; + std::optional<DisplayViewport> result = std::nullopt; + for (const DisplayViewport& currentViewport : mDisplays) { + if (uniqueDisplayId == currentViewport.uniqueId) { + result = std::make_optional(currentViewport); + count++; + } + } + if (count > 1) { + ALOGE("Found %zu viewports with uniqueId %s, but expected 1 at most", + count, uniqueDisplayId.c_str()); + } + return result; +} + +std::optional<DisplayViewport> InputReaderConfiguration::getDisplayViewportByType(ViewportType type) + const { + size_t count = 0; + std::optional<DisplayViewport> result = std::nullopt; + for (const DisplayViewport& currentViewport : mDisplays) { + // Return the first match + if (currentViewport.type == type && !result) { + result = std::make_optional(currentViewport); + count++; + } + } + if (count > 1) { + ALOGE("Found %zu viewports with type %s, but expected 1 at most", + count, viewportTypeToString(type)); + } + return result; +} + +std::optional<DisplayViewport> InputReaderConfiguration::getDisplayViewportByPort( + uint8_t displayPort) const { for (const DisplayViewport& currentViewport : mDisplays) { - if (currentViewport.type == viewportType) { - if (uniqueDisplayId.empty() || - (!uniqueDisplayId.empty() && uniqueDisplayId == currentViewport.uniqueId)) { - return std::make_optional(currentViewport); - } + const std::optional<uint8_t>& physicalPort = currentViewport.physicalPort; + if (physicalPort && (*physicalPort == displayPort)) { + return std::make_optional(currentViewport); } } return std::nullopt; |