blob: 4d4f070071bd678343bfb1e96a4b61aa0efb47f9 [file] [log] [blame]
Sean Paul6a55e9f2015-04-30 15:31:06 -04001/*
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 Stratiienkobde95662022-12-10 20:27:58 +020017#pragma once
Sean Paul6a55e9f2015-04-30 15:31:06 -040018
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030019#include <xf86drmMode.h>
20
Roman Stratiienkoe78235c2021-12-23 17:36:12 +020021#include <cstdint>
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030022#include <string>
23#include <vector>
24
Roman Stratiienko13cc3662020-08-29 21:35:39 +030025#include "DrmEncoder.h"
26#include "DrmMode.h"
27#include "DrmProperty.h"
Roman Stratiienko3e8ce572021-09-29 12:46:28 +030028#include "DrmUnique.h"
Tim Van Pattena2f3efa2024-10-15 17:44:54 -060029#include "compositor/DisplayInfo.h"
Sasha McIntoshf8c14112024-12-11 12:03:32 -050030#include "utils/EdidWrapper.h"
Sasha McIntosh5294f092024-09-18 18:14:54 -040031
Sean Paul6a55e9f2015-04-30 15:31:06 -040032namespace android {
33
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +010034class DrmDevice;
Sean Paul6a55e9f2015-04-30 15:31:06 -040035
Sasha McIntoshf8c14112024-12-11 12:03:32 -050036using EdidWrapperUnique = std::unique_ptr<EdidWrapper>;
37
Roman Stratiienkocad8e0c2022-01-31 16:40:16 +020038class DrmConnector : public PipelineBindable<DrmConnector> {
Sean Paul6a55e9f2015-04-30 15:31:06 -040039 public:
Roman Stratiienko650299a2022-01-30 23:46:10 +020040 static auto CreateInstance(DrmDevice &dev, uint32_t connector_id,
41 uint32_t index) -> std::unique_ptr<DrmConnector>;
42
Zach Reiznerff30b522015-10-28 19:08:45 -070043 DrmConnector(const DrmProperty &) = delete;
44 DrmConnector &operator=(const DrmProperty &) = delete;
Sean Paul6a55e9f2015-04-30 15:31:06 -040045
Andrii Chepurnyiadc5d822020-07-10 16:07:03 +030046 int UpdateEdidProperty();
Roman Stratiienko3e8ce572021-09-29 12:46:28 +030047 auto GetEdidBlob() -> DrmModePropertyBlobUnique;
Sasha McIntoshf8c14112024-12-11 12:03:32 -050048 auto GetParsedEdid() -> EdidWrapperUnique & {
49 return edid_wrapper_;
50 }
Sean Paul6a55e9f2015-04-30 15:31:06 -040051
Roman Stratiienko650299a2022-01-30 23:46:10 +020052 auto GetDev() const -> DrmDevice & {
53 return *drm_;
54 }
Sean Paul6a55e9f2015-04-30 15:31:06 -040055
Roman Stratiienko650299a2022-01-30 23:46:10 +020056 auto GetId() const {
57 return connector_->connector_id;
58 }
Sean Paul6a55e9f2015-04-30 15:31:06 -040059
Roman Stratiienko650299a2022-01-30 23:46:10 +020060 auto GetIndexInResArray() const {
61 return index_in_res_array_;
62 }
Sean Paul6a55e9f2015-04-30 15:31:06 -040063
Roman Stratiienko650299a2022-01-30 23:46:10 +020064 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 Kovalivskyidf882992019-11-04 17:43:40 +020085
Sean Paul6a55e9f2015-04-30 15:31:06 -040086 int UpdateModes();
87
Manasi Navare3f0c01a2024-10-04 18:01:55 +000088 bool IsLinkStatusGood();
89
Roman Stratiienko650299a2022-01-30 23:46:10 +020090 auto &GetModes() const {
Zach Reiznerff30b522015-10-28 19:08:45 -070091 return modes_;
92 }
Sean Paul6a55e9f2015-04-30 15:31:06 -040093
Roman Stratiienko650299a2022-01-30 23:46:10 +020094 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 McIntosh5294f092024-09-18 18:14:54 -0400106 auto &GetColorspaceProperty() const {
107 return colorspace_property_;
108 }
109
110 auto GetColorspacePropertyValue(Colorspace c) {
111 return colorspace_enum_map_[c];
112 }
113
Sasha McIntosh173247b2024-09-18 18:06:52 -0400114 auto &GetContentTypeProperty() const {
115 return content_type_property_;
116 }
117
Sasha McIntoshdfcc8ed2024-11-07 14:40:45 -0500118 auto &GetMinBpcProperty() const {
119 return min_bpc_property_;
120 }
121
Sasha McIntoshf9062b62024-11-12 10:55:06 -0500122 auto &GetHdrOutputMetadataProperty() const {
123 return hdr_output_metadata_property_;
124 }
125
Roman Stratiienkof2c060f2023-09-18 22:46:08 +0300126 auto &GetWritebackFbIdProperty() const {
127 return writeback_fb_id_;
128 }
129
130 auto &GetWritebackOutFenceProperty() const {
131 return writeback_out_fence_;
132 }
133
Tim Van Pattena2f3efa2024-10-15 17:44:54 -0600134 auto &GetPanelOrientationProperty() const {
135 return panel_orientation_;
136 }
137
Roman Stratiienko650299a2022-01-30 23:46:10 +0200138 auto IsConnected() const {
139 return connector_->connection == DRM_MODE_CONNECTED;
140 }
141
142 auto GetMmWidth() const {
143 return connector_->mmWidth;
144 }
145
146 auto GetMmHeight() const {
147 return connector_->mmHeight;
148 };
Sean Paul6a55e9f2015-04-30 15:31:06 -0400149
Tim Van Pattena2f3efa2024-10-15 17:44:54 -0600150 auto GetPanelOrientation() -> std::optional<PanelOrientation>;
151
Sean Paul6a55e9f2015-04-30 15:31:06 -0400152 private:
Roman Stratiienko650299a2022-01-30 23:46:10 +0200153 DrmConnector(DrmModeConnectorUnique connector, DrmDevice *drm, uint32_t index)
154 : connector_(std::move(connector)),
155 drm_(drm),
Tim Van Pattena2f3efa2024-10-15 17:44:54 -0600156 index_in_res_array_(index) {};
Sean Paul6a55e9f2015-04-30 15:31:06 -0400157
Roman Stratiienko650299a2022-01-30 23:46:10 +0200158 DrmModeConnectorUnique connector_;
159 DrmDevice *const drm_;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400160
Sasha McIntosh173247b2024-09-18 18:06:52 -0400161 auto Init() -> bool;
162 auto GetConnectorProperty(const char *prop_name, DrmProperty *property,
163 bool is_optional = false) -> bool;
Sasha McIntoshda080fe2024-11-26 12:17:27 -0500164 auto GetOptionalConnectorProperty(const char *prop_name,
165 DrmProperty *property) -> bool {
166 return GetConnectorProperty(prop_name, property, /*is_optional=*/true);
167 }
Sasha McIntosh173247b2024-09-18 18:06:52 -0400168
Sasha McIntoshf8c14112024-12-11 12:03:32 -0500169 EdidWrapperUnique edid_wrapper_;
170
Roman Stratiienko650299a2022-01-30 23:46:10 +0200171 const uint32_t index_in_res_array_;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400172
Sean Paul6a55e9f2015-04-30 15:31:06 -0400173 std::vector<DrmMode> modes_;
174
175 DrmProperty dpms_property_;
Sean Paul877be972015-06-03 14:08:27 -0400176 DrmProperty crtc_id_property_;
Lowry Li (Arm Technology China)b3d81782019-12-18 14:28:22 +0800177 DrmProperty edid_property_;
Sasha McIntosh5294f092024-09-18 18:14:54 -0400178 DrmProperty colorspace_property_;
Sasha McIntosh173247b2024-09-18 18:06:52 -0400179 DrmProperty content_type_property_;
Sasha McIntoshdfcc8ed2024-11-07 14:40:45 -0500180 DrmProperty min_bpc_property_;
Sasha McIntoshf9062b62024-11-12 10:55:06 -0500181 DrmProperty hdr_output_metadata_property_;
Sasha McIntosh173247b2024-09-18 18:06:52 -0400182
Manasi Navare3f0c01a2024-10-04 18:01:55 +0000183 DrmProperty link_status_property_;
Alexandru Gheorghe364f9572018-03-21 11:40:01 +0000184 DrmProperty writeback_pixel_formats_;
185 DrmProperty writeback_fb_id_;
186 DrmProperty writeback_out_fence_;
Tim Van Pattena2f3efa2024-10-15 17:44:54 -0600187 DrmProperty panel_orientation_;
Sasha McIntosh5294f092024-09-18 18:14:54 -0400188
189 std::map<Colorspace, uint64_t> colorspace_enum_map_;
Tim Van Pattena2f3efa2024-10-15 17:44:54 -0600190 std::map<uint64_t, PanelOrientation> panel_orientation_enum_map_;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400191};
Sean Paulf72cccd2018-08-27 13:59:08 -0400192} // namespace android