blob: be84ae3128a551134dd2e6188f914b60f7bede4e [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 McIntosh5294f092024-09-18 18:14:54 -040030
Sean Paul6a55e9f2015-04-30 15:31:06 -040031namespace android {
32
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +010033class DrmDevice;
Sean Paul6a55e9f2015-04-30 15:31:06 -040034
Roman Stratiienkocad8e0c2022-01-31 16:40:16 +020035class DrmConnector : public PipelineBindable<DrmConnector> {
Sean Paul6a55e9f2015-04-30 15:31:06 -040036 public:
Roman Stratiienko650299a2022-01-30 23:46:10 +020037 static auto CreateInstance(DrmDevice &dev, uint32_t connector_id,
38 uint32_t index) -> std::unique_ptr<DrmConnector>;
39
Zach Reiznerff30b522015-10-28 19:08:45 -070040 DrmConnector(const DrmProperty &) = delete;
41 DrmConnector &operator=(const DrmProperty &) = delete;
Sean Paul6a55e9f2015-04-30 15:31:06 -040042
Andrii Chepurnyiadc5d822020-07-10 16:07:03 +030043 int UpdateEdidProperty();
Roman Stratiienko3e8ce572021-09-29 12:46:28 +030044 auto GetEdidBlob() -> DrmModePropertyBlobUnique;
Sean Paul6a55e9f2015-04-30 15:31:06 -040045
Roman Stratiienko650299a2022-01-30 23:46:10 +020046 auto GetDev() const -> DrmDevice & {
47 return *drm_;
48 }
Sean Paul6a55e9f2015-04-30 15:31:06 -040049
Roman Stratiienko650299a2022-01-30 23:46:10 +020050 auto GetId() const {
51 return connector_->connector_id;
52 }
Sean Paul6a55e9f2015-04-30 15:31:06 -040053
Roman Stratiienko650299a2022-01-30 23:46:10 +020054 auto GetIndexInResArray() const {
55 return index_in_res_array_;
56 }
Sean Paul6a55e9f2015-04-30 15:31:06 -040057
Roman Stratiienko650299a2022-01-30 23:46:10 +020058 auto GetCurrentEncoderId() const {
59 return connector_->encoder_id;
60 }
61
62 auto SupportsEncoder(DrmEncoder &enc) const {
63 for (int i = 0; i < connector_->count_encoders; i++) {
64 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
65 if (connector_->encoders[i] == enc.GetId()) {
66 return true;
67 }
68 }
69
70 return false;
71 }
72
73 bool IsInternal() const;
74 bool IsExternal() const;
75 bool IsWriteback() const;
76 bool IsValid() const;
77
78 std::string GetName() const;
Roman Kovalivskyidf882992019-11-04 17:43:40 +020079
Sean Paul6a55e9f2015-04-30 15:31:06 -040080 int UpdateModes();
81
Manasi Navare3f0c01a2024-10-04 18:01:55 +000082 bool IsLinkStatusGood();
83
Roman Stratiienko650299a2022-01-30 23:46:10 +020084 auto &GetModes() const {
Zach Reiznerff30b522015-10-28 19:08:45 -070085 return modes_;
86 }
Sean Paul6a55e9f2015-04-30 15:31:06 -040087
Roman Stratiienko650299a2022-01-30 23:46:10 +020088 auto &GetDpmsProperty() const {
89 return dpms_property_;
90 }
91
92 auto &GetCrtcIdProperty() const {
93 return crtc_id_property_;
94 }
95
96 auto &GetEdidProperty() const {
97 return edid_property_;
98 }
99
Sasha McIntosh5294f092024-09-18 18:14:54 -0400100 auto &GetColorspaceProperty() const {
101 return colorspace_property_;
102 }
103
104 auto GetColorspacePropertyValue(Colorspace c) {
105 return colorspace_enum_map_[c];
106 }
107
Sasha McIntosh173247b2024-09-18 18:06:52 -0400108 auto &GetContentTypeProperty() const {
109 return content_type_property_;
110 }
111
Roman Stratiienkof2c060f2023-09-18 22:46:08 +0300112 auto &GetWritebackFbIdProperty() const {
113 return writeback_fb_id_;
114 }
115
116 auto &GetWritebackOutFenceProperty() const {
117 return writeback_out_fence_;
118 }
119
Tim Van Pattena2f3efa2024-10-15 17:44:54 -0600120 auto &GetPanelOrientationProperty() const {
121 return panel_orientation_;
122 }
123
Roman Stratiienko650299a2022-01-30 23:46:10 +0200124 auto IsConnected() const {
125 return connector_->connection == DRM_MODE_CONNECTED;
126 }
127
128 auto GetMmWidth() const {
129 return connector_->mmWidth;
130 }
131
132 auto GetMmHeight() const {
133 return connector_->mmHeight;
134 };
Sean Paul6a55e9f2015-04-30 15:31:06 -0400135
Tim Van Pattena2f3efa2024-10-15 17:44:54 -0600136 auto GetPanelOrientation() -> std::optional<PanelOrientation>;
137
Sean Paul6a55e9f2015-04-30 15:31:06 -0400138 private:
Roman Stratiienko650299a2022-01-30 23:46:10 +0200139 DrmConnector(DrmModeConnectorUnique connector, DrmDevice *drm, uint32_t index)
140 : connector_(std::move(connector)),
141 drm_(drm),
Tim Van Pattena2f3efa2024-10-15 17:44:54 -0600142 index_in_res_array_(index) {};
Sean Paul6a55e9f2015-04-30 15:31:06 -0400143
Roman Stratiienko650299a2022-01-30 23:46:10 +0200144 DrmModeConnectorUnique connector_;
145 DrmDevice *const drm_;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400146
Sasha McIntosh173247b2024-09-18 18:06:52 -0400147 auto Init() -> bool;
148 auto GetConnectorProperty(const char *prop_name, DrmProperty *property,
149 bool is_optional = false) -> bool;
150
Roman Stratiienko650299a2022-01-30 23:46:10 +0200151 const uint32_t index_in_res_array_;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400152
Sean Paul6a55e9f2015-04-30 15:31:06 -0400153 std::vector<DrmMode> modes_;
154
155 DrmProperty dpms_property_;
Sean Paul877be972015-06-03 14:08:27 -0400156 DrmProperty crtc_id_property_;
Lowry Li (Arm Technology China)b3d81782019-12-18 14:28:22 +0800157 DrmProperty edid_property_;
Sasha McIntosh5294f092024-09-18 18:14:54 -0400158 DrmProperty colorspace_property_;
Sasha McIntosh173247b2024-09-18 18:06:52 -0400159 DrmProperty content_type_property_;
160
Manasi Navare3f0c01a2024-10-04 18:01:55 +0000161 DrmProperty link_status_property_;
Alexandru Gheorghe364f9572018-03-21 11:40:01 +0000162 DrmProperty writeback_pixel_formats_;
163 DrmProperty writeback_fb_id_;
164 DrmProperty writeback_out_fence_;
Tim Van Pattena2f3efa2024-10-15 17:44:54 -0600165 DrmProperty panel_orientation_;
Sasha McIntosh5294f092024-09-18 18:14:54 -0400166
167 std::map<Colorspace, uint64_t> colorspace_enum_map_;
Tim Van Pattena2f3efa2024-10-15 17:44:54 -0600168 std::map<uint64_t, PanelOrientation> panel_orientation_enum_map_;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400169};
Sean Paulf72cccd2018-08-27 13:59:08 -0400170} // namespace android