blob: 6140e6ccff3c0767b09f8c618b2799a199f6f3d3 [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
Sean Paul6a55e9f2015-04-30 15:31:06 -040030namespace android {
31
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +010032class DrmDevice;
Sean Paul6a55e9f2015-04-30 15:31:06 -040033
Roman Stratiienkocad8e0c2022-01-31 16:40:16 +020034class DrmConnector : public PipelineBindable<DrmConnector> {
Sean Paul6a55e9f2015-04-30 15:31:06 -040035 public:
Roman Stratiienko650299a2022-01-30 23:46:10 +020036 static auto CreateInstance(DrmDevice &dev, uint32_t connector_id,
37 uint32_t index) -> std::unique_ptr<DrmConnector>;
38
Zach Reiznerff30b522015-10-28 19:08:45 -070039 DrmConnector(const DrmProperty &) = delete;
40 DrmConnector &operator=(const DrmProperty &) = delete;
Sean Paul6a55e9f2015-04-30 15:31:06 -040041
Andrii Chepurnyiadc5d822020-07-10 16:07:03 +030042 int UpdateEdidProperty();
Roman Stratiienko3e8ce572021-09-29 12:46:28 +030043 auto GetEdidBlob() -> DrmModePropertyBlobUnique;
Sean Paul6a55e9f2015-04-30 15:31:06 -040044
Roman Stratiienko650299a2022-01-30 23:46:10 +020045 auto GetDev() const -> DrmDevice & {
46 return *drm_;
47 }
Sean Paul6a55e9f2015-04-30 15:31:06 -040048
Roman Stratiienko650299a2022-01-30 23:46:10 +020049 auto GetId() const {
50 return connector_->connector_id;
51 }
Sean Paul6a55e9f2015-04-30 15:31:06 -040052
Roman Stratiienko650299a2022-01-30 23:46:10 +020053 auto GetIndexInResArray() const {
54 return index_in_res_array_;
55 }
Sean Paul6a55e9f2015-04-30 15:31:06 -040056
Roman Stratiienko650299a2022-01-30 23:46:10 +020057 auto GetCurrentEncoderId() const {
58 return connector_->encoder_id;
59 }
60
61 auto SupportsEncoder(DrmEncoder &enc) const {
62 for (int i = 0; i < connector_->count_encoders; i++) {
63 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
64 if (connector_->encoders[i] == enc.GetId()) {
65 return true;
66 }
67 }
68
69 return false;
70 }
71
72 bool IsInternal() const;
73 bool IsExternal() const;
74 bool IsWriteback() const;
75 bool IsValid() const;
76
77 std::string GetName() const;
Roman Kovalivskyidf882992019-11-04 17:43:40 +020078
Sean Paul6a55e9f2015-04-30 15:31:06 -040079 int UpdateModes();
80
Roman Stratiienko650299a2022-01-30 23:46:10 +020081 auto &GetModes() const {
Zach Reiznerff30b522015-10-28 19:08:45 -070082 return modes_;
83 }
Sean Paul6a55e9f2015-04-30 15:31:06 -040084
Roman Stratiienko650299a2022-01-30 23:46:10 +020085 auto &GetDpmsProperty() const {
86 return dpms_property_;
87 }
88
89 auto &GetCrtcIdProperty() const {
90 return crtc_id_property_;
91 }
92
93 auto &GetEdidProperty() const {
94 return edid_property_;
95 }
96
Sasha McIntosh173247b2024-09-18 18:06:52 -040097 auto &GetContentTypeProperty() const {
98 return content_type_property_;
99 }
100
Roman Stratiienkof2c060f2023-09-18 22:46:08 +0300101 auto &GetWritebackFbIdProperty() const {
102 return writeback_fb_id_;
103 }
104
105 auto &GetWritebackOutFenceProperty() const {
106 return writeback_out_fence_;
107 }
108
Roman Stratiienko650299a2022-01-30 23:46:10 +0200109 auto IsConnected() const {
110 return connector_->connection == DRM_MODE_CONNECTED;
111 }
112
113 auto GetMmWidth() const {
114 return connector_->mmWidth;
115 }
116
117 auto GetMmHeight() const {
118 return connector_->mmHeight;
119 };
Sean Paul6a55e9f2015-04-30 15:31:06 -0400120
121 private:
Roman Stratiienko650299a2022-01-30 23:46:10 +0200122 DrmConnector(DrmModeConnectorUnique connector, DrmDevice *drm, uint32_t index)
123 : connector_(std::move(connector)),
124 drm_(drm),
125 index_in_res_array_(index){};
Sean Paul6a55e9f2015-04-30 15:31:06 -0400126
Roman Stratiienko650299a2022-01-30 23:46:10 +0200127 DrmModeConnectorUnique connector_;
128 DrmDevice *const drm_;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400129
Sasha McIntosh173247b2024-09-18 18:06:52 -0400130 auto Init() -> bool;
131 auto GetConnectorProperty(const char *prop_name, DrmProperty *property,
132 bool is_optional = false) -> bool;
133
Roman Stratiienko650299a2022-01-30 23:46:10 +0200134 const uint32_t index_in_res_array_;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400135
Sean Paul6a55e9f2015-04-30 15:31:06 -0400136 std::vector<DrmMode> modes_;
137
138 DrmProperty dpms_property_;
Sean Paul877be972015-06-03 14:08:27 -0400139 DrmProperty crtc_id_property_;
Lowry Li (Arm Technology China)b3d81782019-12-18 14:28:22 +0800140 DrmProperty edid_property_;
Sasha McIntosh173247b2024-09-18 18:06:52 -0400141 DrmProperty content_type_property_;
142
Alexandru Gheorghe364f9572018-03-21 11:40:01 +0000143 DrmProperty writeback_pixel_formats_;
144 DrmProperty writeback_fb_id_;
145 DrmProperty writeback_out_fence_;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400146};
Sean Paulf72cccd2018-08-27 13:59:08 -0400147} // namespace android