blob: 0c7a58ee71e849294953d41c7a66e78f7bdaf86a [file] [log] [blame]
Dominik Laskowskib363c4c2022-08-02 14:03:41 -07001/*
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 Laskowski788945b2022-08-30 12:10:56 -070017#include <algorithm>
Dominik Laskowskib363c4c2022-08-02 14:03:41 -070018#include <functional>
19#include <utility>
20
21#include <ftl/algorithm.h>
22#include <ftl/enum.h>
Dominik Laskowski788945b2022-08-30 12:10:56 -070023#include <ui/DebugUtils.h>
Dominik Laskowskib363c4c2022-08-02 14:03:41 -070024
25#include "DisplaySnapshot.h"
26
27namespace android::display {
28
29DisplaySnapshot::DisplaySnapshot(PhysicalDisplayId displayId,
30 ui::DisplayConnectionType connectionType,
Dominik Laskowski788945b2022-08-30 12:10:56 -070031 DisplayModes&& displayModes, ui::ColorModes&& colorModes,
Dominik Laskowskib363c4c2022-08-02 14:03:41 -070032 std::optional<DeviceProductInfo>&& deviceProductInfo)
33 : mDisplayId(displayId),
34 mConnectionType(connectionType),
35 mDisplayModes(std::move(displayModes)),
Dominik Laskowski788945b2022-08-30 12:10:56 -070036 mColorModes(std::move(colorModes)),
Dominik Laskowskib363c4c2022-08-02 14:03:41 -070037 mDeviceProductInfo(std::move(deviceProductInfo)) {}
38
39std::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 Laskowski788945b2022-08-30 12:10:56 -070047ui::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 Laskowskie70461a2022-08-30 14:42:01 -070062void DisplaySnapshot::dump(utils::Dumper& dumper) const {
63 using namespace std::string_view_literals;
Dominik Laskowskib363c4c2022-08-02 14:03:41 -070064
Dominik Laskowskie70461a2022-08-30 14:42:01 -070065 dumper.dump("connectionType"sv, ftl::enum_string(mConnectionType));
Dominik Laskowski788945b2022-08-30 12:10:56 -070066
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 Laskowskie70461a2022-08-30 14:42:01 -070075 dumper.dump("deviceProductInfo"sv, mDeviceProductInfo);
Dominik Laskowskib363c4c2022-08-02 14:03:41 -070076}
77
78} // namespace android::display