Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2022 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <functional> |
| 18 | #include <utility> |
| 19 | |
| 20 | #include <ftl/algorithm.h> |
| 21 | #include <ftl/enum.h> |
| 22 | |
| 23 | #include "DisplaySnapshot.h" |
| 24 | |
| 25 | namespace android::display { |
| 26 | |
| 27 | DisplaySnapshot::DisplaySnapshot(PhysicalDisplayId displayId, |
| 28 | ui::DisplayConnectionType connectionType, |
| 29 | DisplayModes&& displayModes, |
| 30 | std::optional<DeviceProductInfo>&& deviceProductInfo) |
| 31 | : mDisplayId(displayId), |
| 32 | mConnectionType(connectionType), |
| 33 | mDisplayModes(std::move(displayModes)), |
| 34 | mDeviceProductInfo(std::move(deviceProductInfo)) {} |
| 35 | |
| 36 | std::optional<DisplayModeId> DisplaySnapshot::translateModeId(hal::HWConfigId hwcId) const { |
| 37 | return ftl::find_if(mDisplayModes, |
| 38 | [hwcId](const DisplayModes::value_type& pair) { |
| 39 | return pair.second->getHwcId() == hwcId; |
| 40 | }) |
| 41 | .transform(&ftl::to_key<DisplayModes>); |
| 42 | } |
| 43 | |
| 44 | void DisplaySnapshot::dump(std::string& out) const { |
| 45 | using namespace std::string_literals; |
| 46 | |
| 47 | out += " connectionType="s; |
| 48 | out += ftl::enum_string(mConnectionType); |
| 49 | |
| 50 | out += "\n deviceProductInfo="s; |
| 51 | if (mDeviceProductInfo) { |
| 52 | mDeviceProductInfo->dump(out); |
| 53 | } else { |
| 54 | out += "{}"s; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | } // namespace android::display |