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 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 17 | #include <algorithm> |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 18 | #include <functional> |
| 19 | #include <utility> |
| 20 | |
| 21 | #include <ftl/algorithm.h> |
| 22 | #include <ftl/enum.h> |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 23 | #include <ui/DebugUtils.h> |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 24 | |
| 25 | #include "DisplaySnapshot.h" |
| 26 | |
| 27 | namespace android::display { |
| 28 | |
| 29 | DisplaySnapshot::DisplaySnapshot(PhysicalDisplayId displayId, |
| 30 | ui::DisplayConnectionType connectionType, |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 31 | DisplayModes&& displayModes, ui::ColorModes&& colorModes, |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 32 | std::optional<DeviceProductInfo>&& deviceProductInfo) |
| 33 | : mDisplayId(displayId), |
| 34 | mConnectionType(connectionType), |
| 35 | mDisplayModes(std::move(displayModes)), |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 36 | mColorModes(std::move(colorModes)), |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 37 | mDeviceProductInfo(std::move(deviceProductInfo)) {} |
| 38 | |
| 39 | std::optional<DisplayModeId> DisplaySnapshot::translateModeId(hal::HWConfigId hwcId) const { |
| 40 | return ftl::find_if(mDisplayModes, |
| 41 | [hwcId](const DisplayModes::value_type& pair) { |
| 42 | return pair.second->getHwcId() == hwcId; |
| 43 | }) |
| 44 | .transform(&ftl::to_key<DisplayModes>); |
| 45 | } |
| 46 | |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 47 | ui::ColorModes DisplaySnapshot::filterColorModes(bool supportsWideColor) const { |
| 48 | ui::ColorModes modes = mColorModes; |
| 49 | |
| 50 | // If the display is internal and the configuration claims it's not wide color capable, filter |
| 51 | // out all wide color modes. The typical reason why this happens is that the hardware is not |
| 52 | // good enough to support GPU composition of wide color, and thus the OEMs choose to disable |
| 53 | // this capability. |
| 54 | if (mConnectionType == ui::DisplayConnectionType::Internal && !supportsWideColor) { |
| 55 | const auto it = std::remove_if(modes.begin(), modes.end(), ui::isWideColorMode); |
| 56 | modes.erase(it, modes.end()); |
| 57 | } |
| 58 | |
| 59 | return modes; |
| 60 | } |
| 61 | |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 62 | void DisplaySnapshot::dump(utils::Dumper& dumper) const { |
| 63 | using namespace std::string_view_literals; |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 64 | |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 65 | dumper.dump("connectionType"sv, ftl::enum_string(mConnectionType)); |
Dominik Laskowski | 788945b | 2022-08-30 12:10:56 -0700 | [diff] [blame] | 66 | |
| 67 | dumper.dump("colorModes"sv); |
| 68 | { |
| 69 | utils::Dumper::Indent indent(dumper); |
| 70 | for (const auto mode : mColorModes) { |
| 71 | dumper.dump({}, decodeColorMode(mode)); |
| 72 | } |
| 73 | } |
| 74 | |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 75 | dumper.dump("deviceProductInfo"sv, mDeviceProductInfo); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | } // namespace android::display |