blob: 9186f0791af47c5062e8d3c2bd783b14bf31f07c [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"
Sean Paul6a55e9f2015-04-30 15:31:06 -040029
Sasha McIntosh5294f092024-09-18 18:14:54 -040030#include "compositor/ColorInfo.h"
31
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
Roman Stratiienkocad8e0c2022-01-31 16:40:16 +020036class DrmConnector : public PipelineBindable<DrmConnector> {
Sean Paul6a55e9f2015-04-30 15:31:06 -040037 public:
Roman Stratiienko650299a2022-01-30 23:46:10 +020038 static auto CreateInstance(DrmDevice &dev, uint32_t connector_id,
39 uint32_t index) -> std::unique_ptr<DrmConnector>;
40
Zach Reiznerff30b522015-10-28 19:08:45 -070041 DrmConnector(const DrmProperty &) = delete;
42 DrmConnector &operator=(const DrmProperty &) = delete;
Sean Paul6a55e9f2015-04-30 15:31:06 -040043
Andrii Chepurnyiadc5d822020-07-10 16:07:03 +030044 int UpdateEdidProperty();
Roman Stratiienko3e8ce572021-09-29 12:46:28 +030045 auto GetEdidBlob() -> DrmModePropertyBlobUnique;
Sean Paul6a55e9f2015-04-30 15:31:06 -040046
Roman Stratiienko650299a2022-01-30 23:46:10 +020047 auto GetDev() const -> DrmDevice & {
48 return *drm_;
49 }
Sean Paul6a55e9f2015-04-30 15:31:06 -040050
Roman Stratiienko650299a2022-01-30 23:46:10 +020051 auto GetId() const {
52 return connector_->connector_id;
53 }
Sean Paul6a55e9f2015-04-30 15:31:06 -040054
Roman Stratiienko650299a2022-01-30 23:46:10 +020055 auto GetIndexInResArray() const {
56 return index_in_res_array_;
57 }
Sean Paul6a55e9f2015-04-30 15:31:06 -040058
Roman Stratiienko650299a2022-01-30 23:46:10 +020059 auto GetCurrentEncoderId() const {
60 return connector_->encoder_id;
61 }
62
63 auto SupportsEncoder(DrmEncoder &enc) const {
64 for (int i = 0; i < connector_->count_encoders; i++) {
65 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
66 if (connector_->encoders[i] == enc.GetId()) {
67 return true;
68 }
69 }
70
71 return false;
72 }
73
74 bool IsInternal() const;
75 bool IsExternal() const;
76 bool IsWriteback() const;
77 bool IsValid() const;
78
79 std::string GetName() const;
Roman Kovalivskyidf882992019-11-04 17:43:40 +020080
Sean Paul6a55e9f2015-04-30 15:31:06 -040081 int UpdateModes();
82
Manasi Navare3f0c01a2024-10-04 18:01:55 +000083 bool IsLinkStatusGood();
84
Roman Stratiienko650299a2022-01-30 23:46:10 +020085 auto &GetModes() const {
Zach Reiznerff30b522015-10-28 19:08:45 -070086 return modes_;
87 }
Sean Paul6a55e9f2015-04-30 15:31:06 -040088
Roman Stratiienko650299a2022-01-30 23:46:10 +020089 auto &GetDpmsProperty() const {
90 return dpms_property_;
91 }
92
93 auto &GetCrtcIdProperty() const {
94 return crtc_id_property_;
95 }
96
97 auto &GetEdidProperty() const {
98 return edid_property_;
99 }
100
Sasha McIntosh5294f092024-09-18 18:14:54 -0400101 auto &GetColorspaceProperty() const {
102 return colorspace_property_;
103 }
104
105 auto GetColorspacePropertyValue(Colorspace c) {
106 return colorspace_enum_map_[c];
107 }
108
Sasha McIntosh173247b2024-09-18 18:06:52 -0400109 auto &GetContentTypeProperty() const {
110 return content_type_property_;
111 }
112
Roman Stratiienkof2c060f2023-09-18 22:46:08 +0300113 auto &GetWritebackFbIdProperty() const {
114 return writeback_fb_id_;
115 }
116
117 auto &GetWritebackOutFenceProperty() const {
118 return writeback_out_fence_;
119 }
120
Roman Stratiienko650299a2022-01-30 23:46:10 +0200121 auto IsConnected() const {
122 return connector_->connection == DRM_MODE_CONNECTED;
123 }
124
125 auto GetMmWidth() const {
126 return connector_->mmWidth;
127 }
128
129 auto GetMmHeight() const {
130 return connector_->mmHeight;
131 };
Sean Paul6a55e9f2015-04-30 15:31:06 -0400132
133 private:
Roman Stratiienko650299a2022-01-30 23:46:10 +0200134 DrmConnector(DrmModeConnectorUnique connector, DrmDevice *drm, uint32_t index)
135 : connector_(std::move(connector)),
136 drm_(drm),
137 index_in_res_array_(index){};
Sean Paul6a55e9f2015-04-30 15:31:06 -0400138
Roman Stratiienko650299a2022-01-30 23:46:10 +0200139 DrmModeConnectorUnique connector_;
140 DrmDevice *const drm_;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400141
Sasha McIntosh173247b2024-09-18 18:06:52 -0400142 auto Init() -> bool;
143 auto GetConnectorProperty(const char *prop_name, DrmProperty *property,
144 bool is_optional = false) -> bool;
145
Roman Stratiienko650299a2022-01-30 23:46:10 +0200146 const uint32_t index_in_res_array_;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400147
Sean Paul6a55e9f2015-04-30 15:31:06 -0400148 std::vector<DrmMode> modes_;
149
150 DrmProperty dpms_property_;
Sean Paul877be972015-06-03 14:08:27 -0400151 DrmProperty crtc_id_property_;
Lowry Li (Arm Technology China)b3d81782019-12-18 14:28:22 +0800152 DrmProperty edid_property_;
Sasha McIntosh5294f092024-09-18 18:14:54 -0400153 DrmProperty colorspace_property_;
Sasha McIntosh173247b2024-09-18 18:06:52 -0400154 DrmProperty content_type_property_;
155
Manasi Navare3f0c01a2024-10-04 18:01:55 +0000156 DrmProperty link_status_property_;
Alexandru Gheorghe364f9572018-03-21 11:40:01 +0000157 DrmProperty writeback_pixel_formats_;
158 DrmProperty writeback_fb_id_;
159 DrmProperty writeback_out_fence_;
Sasha McIntosh5294f092024-09-18 18:14:54 -0400160
161 std::map<Colorspace, uint64_t> colorspace_enum_map_;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400162};
Sean Paulf72cccd2018-08-27 13:59:08 -0400163} // namespace android