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