Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | |
Roman Stratiienko | bde9566 | 2022-12-10 20:27:58 +0200 | [diff] [blame] | 17 | #pragma once |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 18 | |
Roman Stratiienko | aa3cd54 | 2020-08-29 11:26:16 +0300 | [diff] [blame] | 19 | #include <xf86drmMode.h> |
| 20 | |
Roman Stratiienko | e78235c | 2021-12-23 17:36:12 +0200 | [diff] [blame] | 21 | #include <cstdint> |
Roman Stratiienko | aa3cd54 | 2020-08-29 11:26:16 +0300 | [diff] [blame] | 22 | #include <string> |
| 23 | #include <vector> |
| 24 | |
Roman Stratiienko | 13cc366 | 2020-08-29 21:35:39 +0300 | [diff] [blame] | 25 | #include "DrmEncoder.h" |
| 26 | #include "DrmMode.h" |
| 27 | #include "DrmProperty.h" |
Roman Stratiienko | 3e8ce57 | 2021-09-29 12:46:28 +0300 | [diff] [blame] | 28 | #include "DrmUnique.h" |
Tim Van Patten | a2f3efa | 2024-10-15 17:44:54 -0600 | [diff] [blame] | 29 | #include "compositor/DisplayInfo.h" |
Sasha McIntosh | f8c1411 | 2024-12-11 12:03:32 -0500 | [diff] [blame] | 30 | #include "utils/EdidWrapper.h" |
Sasha McIntosh | 5294f09 | 2024-09-18 18:14:54 -0400 | [diff] [blame] | 31 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 32 | namespace android { |
| 33 | |
Alexandru Gheorghe | 0f5abd7 | 2018-05-01 14:37:10 +0100 | [diff] [blame] | 34 | class DrmDevice; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 35 | |
Sasha McIntosh | f8c1411 | 2024-12-11 12:03:32 -0500 | [diff] [blame] | 36 | using EdidWrapperUnique = std::unique_ptr<EdidWrapper>; |
| 37 | |
Roman Stratiienko | cad8e0c | 2022-01-31 16:40:16 +0200 | [diff] [blame] | 38 | class DrmConnector : public PipelineBindable<DrmConnector> { |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 39 | public: |
Roman Stratiienko | 650299a | 2022-01-30 23:46:10 +0200 | [diff] [blame] | 40 | static auto CreateInstance(DrmDevice &dev, uint32_t connector_id, |
| 41 | uint32_t index) -> std::unique_ptr<DrmConnector>; |
| 42 | |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame] | 43 | DrmConnector(const DrmProperty &) = delete; |
| 44 | DrmConnector &operator=(const DrmProperty &) = delete; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 45 | |
Andrii Chepurnyi | adc5d82 | 2020-07-10 16:07:03 +0300 | [diff] [blame] | 46 | int UpdateEdidProperty(); |
Roman Stratiienko | 3e8ce57 | 2021-09-29 12:46:28 +0300 | [diff] [blame] | 47 | auto GetEdidBlob() -> DrmModePropertyBlobUnique; |
Sasha McIntosh | f8c1411 | 2024-12-11 12:03:32 -0500 | [diff] [blame] | 48 | auto GetParsedEdid() -> EdidWrapperUnique & { |
| 49 | return edid_wrapper_; |
| 50 | } |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 51 | |
Roman Stratiienko | 650299a | 2022-01-30 23:46:10 +0200 | [diff] [blame] | 52 | auto GetDev() const -> DrmDevice & { |
| 53 | return *drm_; |
| 54 | } |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 55 | |
Roman Stratiienko | 650299a | 2022-01-30 23:46:10 +0200 | [diff] [blame] | 56 | auto GetId() const { |
| 57 | return connector_->connector_id; |
| 58 | } |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 59 | |
Roman Stratiienko | 650299a | 2022-01-30 23:46:10 +0200 | [diff] [blame] | 60 | auto GetIndexInResArray() const { |
| 61 | return index_in_res_array_; |
| 62 | } |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 63 | |
Roman Stratiienko | 650299a | 2022-01-30 23:46:10 +0200 | [diff] [blame] | 64 | auto GetCurrentEncoderId() const { |
| 65 | return connector_->encoder_id; |
| 66 | } |
| 67 | |
| 68 | auto SupportsEncoder(DrmEncoder &enc) const { |
| 69 | for (int i = 0; i < connector_->count_encoders; i++) { |
| 70 | // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) |
| 71 | if (connector_->encoders[i] == enc.GetId()) { |
| 72 | return true; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | return false; |
| 77 | } |
| 78 | |
| 79 | bool IsInternal() const; |
| 80 | bool IsExternal() const; |
| 81 | bool IsWriteback() const; |
| 82 | bool IsValid() const; |
| 83 | |
| 84 | std::string GetName() const; |
Roman Kovalivskyi | df88299 | 2019-11-04 17:43:40 +0200 | [diff] [blame] | 85 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 86 | int UpdateModes(); |
| 87 | |
Manasi Navare | 3f0c01a | 2024-10-04 18:01:55 +0000 | [diff] [blame] | 88 | bool IsLinkStatusGood(); |
| 89 | |
Roman Stratiienko | 650299a | 2022-01-30 23:46:10 +0200 | [diff] [blame] | 90 | auto &GetModes() const { |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame] | 91 | return modes_; |
| 92 | } |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 93 | |
Roman Stratiienko | 650299a | 2022-01-30 23:46:10 +0200 | [diff] [blame] | 94 | auto &GetDpmsProperty() const { |
| 95 | return dpms_property_; |
| 96 | } |
| 97 | |
| 98 | auto &GetCrtcIdProperty() const { |
| 99 | return crtc_id_property_; |
| 100 | } |
| 101 | |
| 102 | auto &GetEdidProperty() const { |
| 103 | return edid_property_; |
| 104 | } |
| 105 | |
Sasha McIntosh | 5294f09 | 2024-09-18 18:14:54 -0400 | [diff] [blame] | 106 | auto &GetColorspaceProperty() const { |
| 107 | return colorspace_property_; |
| 108 | } |
| 109 | |
| 110 | auto GetColorspacePropertyValue(Colorspace c) { |
| 111 | return colorspace_enum_map_[c]; |
| 112 | } |
| 113 | |
Sasha McIntosh | 173247b | 2024-09-18 18:06:52 -0400 | [diff] [blame] | 114 | auto &GetContentTypeProperty() const { |
| 115 | return content_type_property_; |
| 116 | } |
| 117 | |
Sasha McIntosh | f9062b6 | 2024-11-12 10:55:06 -0500 | [diff] [blame] | 118 | auto &GetHdrOutputMetadataProperty() const { |
| 119 | return hdr_output_metadata_property_; |
| 120 | } |
| 121 | |
Roman Stratiienko | f2c060f | 2023-09-18 22:46:08 +0300 | [diff] [blame] | 122 | auto &GetWritebackFbIdProperty() const { |
| 123 | return writeback_fb_id_; |
| 124 | } |
| 125 | |
| 126 | auto &GetWritebackOutFenceProperty() const { |
| 127 | return writeback_out_fence_; |
| 128 | } |
| 129 | |
Tim Van Patten | a2f3efa | 2024-10-15 17:44:54 -0600 | [diff] [blame] | 130 | auto &GetPanelOrientationProperty() const { |
| 131 | return panel_orientation_; |
| 132 | } |
| 133 | |
Roman Stratiienko | 650299a | 2022-01-30 23:46:10 +0200 | [diff] [blame] | 134 | auto IsConnected() const { |
| 135 | return connector_->connection == DRM_MODE_CONNECTED; |
| 136 | } |
| 137 | |
| 138 | auto GetMmWidth() const { |
| 139 | return connector_->mmWidth; |
| 140 | } |
| 141 | |
| 142 | auto GetMmHeight() const { |
| 143 | return connector_->mmHeight; |
| 144 | }; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 145 | |
Tim Van Patten | a2f3efa | 2024-10-15 17:44:54 -0600 | [diff] [blame] | 146 | auto GetPanelOrientation() -> std::optional<PanelOrientation>; |
| 147 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 148 | private: |
Roman Stratiienko | 650299a | 2022-01-30 23:46:10 +0200 | [diff] [blame] | 149 | DrmConnector(DrmModeConnectorUnique connector, DrmDevice *drm, uint32_t index) |
| 150 | : connector_(std::move(connector)), |
| 151 | drm_(drm), |
Tim Van Patten | a2f3efa | 2024-10-15 17:44:54 -0600 | [diff] [blame] | 152 | index_in_res_array_(index) {}; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 153 | |
Roman Stratiienko | 650299a | 2022-01-30 23:46:10 +0200 | [diff] [blame] | 154 | DrmModeConnectorUnique connector_; |
| 155 | DrmDevice *const drm_; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 156 | |
Sasha McIntosh | 173247b | 2024-09-18 18:06:52 -0400 | [diff] [blame] | 157 | auto Init() -> bool; |
| 158 | auto GetConnectorProperty(const char *prop_name, DrmProperty *property, |
| 159 | bool is_optional = false) -> bool; |
Sasha McIntosh | da080fe | 2024-11-26 12:17:27 -0500 | [diff] [blame] | 160 | auto GetOptionalConnectorProperty(const char *prop_name, |
| 161 | DrmProperty *property) -> bool { |
| 162 | return GetConnectorProperty(prop_name, property, /*is_optional=*/true); |
| 163 | } |
Sasha McIntosh | 173247b | 2024-09-18 18:06:52 -0400 | [diff] [blame] | 164 | |
Sasha McIntosh | f8c1411 | 2024-12-11 12:03:32 -0500 | [diff] [blame] | 165 | EdidWrapperUnique edid_wrapper_; |
| 166 | |
Roman Stratiienko | 650299a | 2022-01-30 23:46:10 +0200 | [diff] [blame] | 167 | const uint32_t index_in_res_array_; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 168 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 169 | std::vector<DrmMode> modes_; |
| 170 | |
| 171 | DrmProperty dpms_property_; |
Sean Paul | 877be97 | 2015-06-03 14:08:27 -0400 | [diff] [blame] | 172 | DrmProperty crtc_id_property_; |
Lowry Li (Arm Technology China) | b3d8178 | 2019-12-18 14:28:22 +0800 | [diff] [blame] | 173 | DrmProperty edid_property_; |
Sasha McIntosh | 5294f09 | 2024-09-18 18:14:54 -0400 | [diff] [blame] | 174 | DrmProperty colorspace_property_; |
Sasha McIntosh | 173247b | 2024-09-18 18:06:52 -0400 | [diff] [blame] | 175 | DrmProperty content_type_property_; |
Sasha McIntosh | f9062b6 | 2024-11-12 10:55:06 -0500 | [diff] [blame] | 176 | DrmProperty hdr_output_metadata_property_; |
Sasha McIntosh | 173247b | 2024-09-18 18:06:52 -0400 | [diff] [blame] | 177 | |
Manasi Navare | 3f0c01a | 2024-10-04 18:01:55 +0000 | [diff] [blame] | 178 | DrmProperty link_status_property_; |
Alexandru Gheorghe | 364f957 | 2018-03-21 11:40:01 +0000 | [diff] [blame] | 179 | DrmProperty writeback_pixel_formats_; |
| 180 | DrmProperty writeback_fb_id_; |
| 181 | DrmProperty writeback_out_fence_; |
Tim Van Patten | a2f3efa | 2024-10-15 17:44:54 -0600 | [diff] [blame] | 182 | DrmProperty panel_orientation_; |
Sasha McIntosh | 5294f09 | 2024-09-18 18:14:54 -0400 | [diff] [blame] | 183 | |
| 184 | std::map<Colorspace, uint64_t> colorspace_enum_map_; |
Tim Van Patten | a2f3efa | 2024-10-15 17:44:54 -0600 | [diff] [blame] | 185 | std::map<uint64_t, PanelOrientation> panel_orientation_enum_map_; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 186 | }; |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 187 | } // namespace android |